In: Statistics and Probability
Install and load the dataset named Carseats (in the ISLR package) into R.
Create a new dataframe that is a copy of Carseats. Create two indicator (dummy) variables:
Bad_Shelf = 1 if ShelveLoc = “Bad”, 0 otherwise
Good_Shelf = 1 if ShelveLoc = “Good”, 0 otherwise
Also, create two interaction variables:
Price_Bad_Shelf = Price* Bad_Shelf
Price_Good_Shelf = Price* Good_Shelf
For Questions 1-2, please estimate a linear regression model (using the lm function) with Sales as the dependent variable and Price, Bad_Shelf, Good_Shelf, Price_Bad_Shelf, and Price_Good_Shelf as independent variables.
Question 1
For the model, does Bad_Shelf have an Intercept significantly (statistically) different from that of the base case?
a) Yes
b) No
c) Maybe
d) Not enough information
Question 2
For the model in Question 2, do the products located on Good_Shelf have a significantly (statistically) different Price coefficient from that of the base case?
a) Yes
b) No
c) Maybe
d) Not enough information
Hi.
The Code:
install.packages("ISLR")
library(ISLR)
data("Carseats")
Bad_Shelf = as.integer(Carseats$ShelveLoc == "Bad")
Good_Shelf = as.integer(Carseats$ShelveLoc == "Good")
Price_Bad_Shelf = Carseats$Price * Bad_Shelf
Price_Good_Shelf = Carseats$Price * Good_Shelf
attach(Carseats)
model1 = lm(Sales ~ Price + Bad_Shelf + Good_Shelf +
Price_Bad_Shelf + Price_Good_Shelf)
summary(model1)
Output
Call:
lm(formula = Sales ~ Price + Bad_Shelf + Good_Shelf +
Price_Bad_Shelf +
Price_Good_Shelf)
Residuals:
Min 1Q Median 3Q Max
-5.9037 -1.3461 -0.0595 1.3679 4.9037
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 13.463465 0.663278 20.298 < 2e-16 ***
Price -0.053236 0.005624 -9.465 < 2e-16 ***
Bad_Shelf -1.630481 1.171616 -1.392 0.164813
Good_Shelf 4.505399 1.202999 3.745 0.000207 ***
Price_Bad_Shelf -0.001984 0.010007 -0.198 0.842907
Price_Good_Shelf -0.012549 0.010050 -1.249 0.212541
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.918 on 394 degrees of freedom
Multiple R-squared: 0.5444, Adjusted R-squared: 0.5386
F-statistic: 94.17 on 5 and 394 DF, p-value: < 2.2e-16
Question 1:
Ans: Option B. No as the intercept of the Bad_shelf is not significant in the model.
Question 2:
Ans: Option B. No. Price on that of Price_Good_Shelf is not significant.