Session 9

Emma Gaucher
Questions 1-10

Data

setwd("~/Downloads")
library(readr)
store.df <- read_csv("~/Downloads/StoreData.csv")

Question 1

library(psych)
describe(store.df$p1sales)
   vars    n   mean    sd median trimmed   mad min max range skew kurtosis
X1    1 2080 133.05 28.37    129  131.08 26.69  73 263   190 0.74     0.66
     se
X1 0.62

Question 2

x<- store.df$p1sales
y<- store.df$p1prom
z<- cor(x,y)
round(z,2)
[1] 0.42

Question 3

x<- store.df$p1sales
y<- store.df$p2prom
Z<- cor(x,y)
round(z,2)
[1] 0.42

Question 4

x<- store.df[4:7]
y<- store.df[8:9]
z<-cor(x,y)
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

Question 5

library(corrgram)
corrgram(store.df[,c(4:7,8:9)], order=FALSE, lower.panel=panel.conf,
         upper.panel=panel.pie, text.panel=panel.txt,
         main="Corrgram - Store")

plot of chunk unnamed-chunk-6

Question 6

cor.test(store.df$p2sales,store.df$p2prom)

    Pearson's product-moment correlation

data:  store.df$p2sales and store.df$p2prom
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 

Question 7

cor.test(store.df$p1sales,store.df$p1prom)

    Pearson's product-moment correlation

data:  store.df$p1sales and store.df$p1prom
t = 21.168, df = 2078, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.3851676 0.4559018
sample estimates:
     cor 
0.421175 

Question 8

lrpepsi <- lm(p2sales ~ p2price, data = store.df)
summary(lrpepsi)

Question 8


Call:
lm(formula = p2sales ~ p2price, data = store.df)

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

Question 9

lrpepsi <- lm(p2sales ~ p2price, data = store.df)
summary(lrpepsi)

Question 9


Call:
lm(formula = p2sales ~ p2price, data = store.df)

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

Question 10