Store Data excercise

Elena Giasi
16th October 2017

StoreData <- read.csv("C:/Users/Elena/Desktop/DAM/SESSION 9/StoreData.csv")
View(StoreData)

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

mean(StoreData$p1sales)
[1] 133.0486
var(StoreData$p1sales)
[1] 805.0044
sd(StoreData$p1sales)
[1] 28.3726

Q2 What is the correlation of the sales of Coke with the promotions of Coke?

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

Q3 What is the correlation of the sales of Coke with the promotions of Pepsi?

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

Q4 Create a correlation matrix of the sales and prices of Coke and Pepsi versus the promotions of Coke and Pepsi. Hint: This should be a 4*2 matrix.

x<-StoreData[4:7]
y<-StoreData[8:9]
z<-cor(x,y)
z
              p1prom      p2prom
p1sales  0.421174952 -0.01334702
p2sales -0.013952850  0.55990301
p1price -0.014731296  0.02426913
p2price -0.001363308 -0.01201736
round(z,2)
        p1prom p2prom
p1sales   0.42  -0.01
p2sales  -0.01   0.56
p1price  -0.01   0.02
p2price   0.00  -0.01

Slide With Plot

Q5 Draw a corrgram illustrating the previous question

plot of chunk unnamed-chunk-6

Q6 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 
#positively correlated

Q7 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 
#negatively correlated

Q8 Run a simple linear regression of the sales of Coke on the price of Coke

fit<-lm(p1sales~p1price,data = StoreData)
summary(fit)

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

Q9 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

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

In both case,the beta's value is negative (-52.7 for p1 and - 35.8 for p2) because (following the low of demand) the quantity demanded (sales) is sensitive to price: as price increases, demand decreases.Also both beta1 are statistically signivicative because it's respective p-value closes to zero. In this case, p1sales are more responsive to price than p2sales because per each increase on p1price by 1, there will be a decrase in p1sales by -52, while for each increase in p2price by 1, there will be a decrease in p2sales of -35.