Академический Документы
Профессиональный Документы
Культура Документы
var_1163<-as.data.frame(t(var_1163))
var_1163<-var_1163[2:25,]
var_1163[,1:10]<-sapply(var_1163[, 1:10], as.character)
var_1163[,1:10]<-sapply(var_1163[, 1:10], as.numeric)
var_1163_str$total<-0
for(i in 1:length(var_1163_str[,1])){
for (j in 1:10){
var_1163_str$total[i]<-var_1163_str$total[i]+var_1163_str[i,j]
}
}
var_1163_media$stores<-var_1163_str$total
var_1163_media$stores<-var_1163_media$stores*1000
var_1163_media$price<-var_1163_media$price*1000
##
## Call:
## lm(formula = var_1163_media$vol[var_1163_media$vol != 0] ~ var_1163_media$
price[var_1163_media$price !=
## 0], data = var_1163_media)
##
## Residuals:
## Min 1Q Median 3Q Max
## -12076 -1162 -3 1614 5354
##
## Coefficients:
## Estimate Std. Error
## (Intercept) 114727.83 22806.67
## var_1163_media$price[var_1163_media$price != 0] -120.12 26.38
## t value Pr(>|t|)
## (Intercept) 5.030 8.69e-05 ***
## var_1163_media$price[var_1163_media$price != 0] -4.553 0.000247 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3643 on 18 degrees of freedom
## Multiple R-squared: 0.5352, Adjusted R-squared: 0.5094
## F-statistic: 20.73 on 1 and 18 DF, p-value: 0.0002466
anova(reg_vol)
Plot
plot(var_1163_media$price[var_1163_media$price!=0],var_1163_media$vol[var_116
3_media$vol!=0],
ylab="Volume sold in L",xlab="Price",
main="Variant-1163(Volume vs price)")
abline(reg_vol)
##
## Call:
## lm(formula = var_1163_media$vol[var_1163_media$vol != 0] ~ var_1163_media$
stores[var_1163_media$stores !=
## 0], data = var_1163_media)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2620.2 -1078.1 -326.7 367.8 6685.6
##
## Coefficients:
## Estimate Std. Error
## (Intercept) -3175.6875 1447.3520
## var_1163_media$stores[var_1163_media$stores != 0] 0.1131 0.0110
## t value Pr(>|t|)
## (Intercept) -2.194 0.0416 *
## var_1163_media$stores[var_1163_media$stores != 0] 10.289 5.75e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2037 on 18 degrees of freedom
## Multiple R-squared: 0.8547, Adjusted R-squared: 0.8466
## F-statistic: 105.9 on 1 and 18 DF, p-value: 5.75e-09
anova(reg_stores)
We can say that with 99.99% probability of being correct that the store
distribution is having some effect on volume sales, which can be explained by
the equation with a standard error of 3643 L. [Y= -3175.7 +113.1x].The Volume
sales accounted for 85.47% of change in volume sales.
plot(var_1163_media$stores[var_1163_media$stores!=0],var_1163_media$vol[var_1
163_media$vol!=0],
xlab="Number of stores",ylab="Volume",
main="Variant-1163(Volume vs No of stores)")
abline(reg_stores)
Multiple regression
reg_mult<-lm(var_1163_media$vol[var_1163_media$vol!=0]~
var_1163_media$stores[var_1163_media$stores!=0]+
var_1163_media$price[var_1163_media$price!=0],
data = var_1163_media)
summary(reg_mult)
##
## Call:
## lm(formula = var_1163_media$vol[var_1163_media$vol != 0] ~ var_1163_media$
stores[var_1163_media$stores !=
## 0] + var_1163_media$price[var_1163_media$price != 0], data = var_1163_
media)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2197.8 -563.4 -117.1 616.2 1850.2
##
## Coefficients:
## Estimate Std. Error
## (Intercept) 5.363e+04 7.379e+03
## var_1163_media$stores[var_1163_media$stores != 0] 9.120e-02 6.032e-03
## var_1163_media$price[var_1163_media$price != 0] -6.258e+01 8.093e+00
## t value Pr(>|t|)
## (Intercept) 7.267 1.32e-06 ***
## var_1163_media$stores[var_1163_media$stores != 0] 15.120 2.73e-11 ***
## var_1163_media$price[var_1163_media$price != 0] -7.733 5.78e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 986.2 on 17 degrees of freedom
## Multiple R-squared: 0.9678, Adjusted R-squared: 0.964
## F-statistic: 255.7 on 2 and 17 DF, p-value: 2.057e-13
anova(reg_mult)
We can say that with 99.99% probability of being correct that the store
distribution and price is having some effect on volume sales, which can be
explained by the equation with a standard error of 986.2 L. [Y= 53626.006 +
0.912 x1 - 62.583x2.The Number of stores and price accounted for 96.78% of
change in volume sales.
The F-value is greater than the table value in Anova table. Hence null is rejected.
So we can say that our model is a significant model.
##
## Attaching package: 'zoo'
dwtest(reg_mult)
##
## Durbin-Watson test
##
## data: reg_mult
## DW = 1.5166, p-value = 0.0718
## alternative hypothesis: true autocorrelation is greater than 0
For homoscedasticity
bptest(reg_mult)
##
## studentized Breusch-Pagan test
##
## data: reg_mult
## BP = 0.47847, df = 2, p-value = 0.7872
plot(predict(reg_mult),residuals(reg_mult))
Normality of residuals
shapiro.test(residuals(reg_mult))
##
## Shapiro-Wilk normality test
##
## data: residuals(reg_mult)
## W = 0.96833, p-value = 0.7194
The errors must be normally distributed. This is done to ensure the randomness
of the errors. Shapiro wilk’s test is done to check normality. Here the null
hypothesis is the residuals are normally distributed and the alternate
hypothesis is the residuals are not normally distributed.The P-value is greater
than the alpha. So we can accept the null hypothesis which says that the errors
are normally distributed. This can further be supported by graphs.
pp_plot<-rstandard(reg_mult)
qqnorm(pp_plot,
ylab="Standardized Residuals",xlab="Normal Scores",
main="Normal PP-Plot of Regression standardized Residual")
qqline(pp_plot)
hist(residuals(reg_mult))
CONCLUSION:
By using the above equation, on increasing the price by 10% i.e. from
864.555(December 2013) to 951.011, and keeping the store distribution same as
December 2013 , the volume sales is decreasing by 38.45%(9987.327±986.2 L)