Ramya L.
16/10/2017
StoreData<-read.csv("StoreData.csv")
mean(StoreData$p1sales)
[1] 133.0486
StdDev<-sqrt(var(StoreData$p1sales))
StdDev
[1] 28.3726
var(StoreData$p1sales)
[1] 805.0044
cor(StoreData$p1sales,StoreData$p1prom)
[1] 0.421175
cor(StoreData$p1sales,StoreData$p2prom)
[1] -0.01334702
x<-StoreData[4:5]
y<-StoreData[8:9]
z<-cor(x,y)
z
p1prom p2prom
p1sales 0.42117495 -0.01334702
p2sales -0.01395285 0.55990301
library(corrgram)
corrgram(StoreData[,c(4:5,8:9)], order=FALSE, lower.panel=panel.conf,upper.panel=panel.pie, text.panel=panel.txt,main="Corrgram - Sales & Promotions")
cor.test(StoreData[,5],StoreData[,9])
Pearson's product-moment correlation
data: StoreData[, 5] and StoreData[, 9]
t = 30.804, df = 2078, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.5296696 0.5887155
sample estimates:
cor
0.559903
cor.test(StoreData[,5],StoreData[,8])
Pearson's product-moment correlation
data: StoreData[, 5] and StoreData[, 8]
t = -0.6361, df = 2078, p-value = 0.5248
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.05689831 0.02904415
sample estimates:
cor
-0.01395285
fit1 <- lm(p1sales ~ p1price, data = StoreData)
summary(fit1)
Call:
lm(formula = p1sales ~ p1price, data = StoreData)
Residuals:
Min 1Q Median 3Q Max
-52.724 -17.454 -2.819 14.463 111.276
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 267.138 4.523 59.06 <2e-16 ***
p1price -52.700 1.766 -29.84 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 23.74 on 2078 degrees of freedom
Multiple R-squared: 0.3, Adjusted R-squared: 0.2997
F-statistic: 890.6 on 1 and 2078 DF, p-value: < 2.2e-16
fit2 <- lm(p2sales ~ p2price, data = StoreData)
summary(fit2)
Call:
lm(formula = p2sales ~ p2price, data = StoreData)
Residuals:
Min 1Q Median 3Q Max
-45.657 -15.657 -3.077 11.400 110.184
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 196.788 3.877 50.76 <2e-16 ***
p2price -35.796 1.425 -25.11 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 21.4 on 2078 degrees of freedom
Multiple R-squared: 0.2328, Adjusted R-squared: 0.2324
F-statistic: 630.6 on 1 and 2078 DF, p-value: < 2.2e-16
fit1$coefficients
(Intercept) p1price
267.13819 -52.70042
fit2$coefficients
(Intercept) p2price
196.78796 -35.79572
Coke is more sensitive than Pepsi as beta of coke is higher