Session 9

Ramya L.
16/10/2017

1.What is the mean, standard deviation and variance of the sales of Coke?

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

2.What is the correlation of the sales of Coke with the promotions of Coke?

cor(StoreData$p1sales,StoreData$p1prom)
[1] 0.421175

3.What is the correlation of the sales of Coke with the promotions of Pepsi?

cor(StoreData$p1sales,StoreData$p2prom)
[1] -0.01334702

4.Create a correlation matrix of the sales and prices of Coke and Pepsi versus the promotions of Coke and Pepsi.

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

5.Draw a corrgram illustrating the previous question

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")

plot of chunk unnamed-chunk-5

6.Test the null hypothesis that the sales of Pepsi are uncorrelated with Pepsi???s 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 

7.Test the null hypothesis that the sales of Pepsi are uncorrelated with Coke???s promotions

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 

8.Run a simple linear regression of the sales of Coke on the price of Coke

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

9.Run another simple linear regression of the sales of Pepsi on the price of Pepsi

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

10.Compare the two simple linear regressions. The sales of which product are more responsive to a change in its price?

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