Question

In: Statistics and Probability

Install and load the dataset named Carseats (in the ISLR package) into R. Create a new...

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

Solutions

Expert Solution

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.


Related Solutions

Install and load the dataset named Carseats (in the ISLR package) into R. Run a multiple...
Install and load the dataset named Carseats (in the ISLR package) into R. Run a multiple linear regression with all the variables. Using the coefficients, write down the model. ( be careful with the qualitative variable ShelveLoc. ) obtain the interaction plot of ShelveLoc and price.
R code: ## 2. __Basic dplyr exercises__ ## Install the package `fueleconomy` and load the dataset...
R code: ## 2. __Basic dplyr exercises__ ## Install the package `fueleconomy` and load the dataset `vehicles`. Answer the following questions. install.packages("fueleconomy") library(fueleconomy) library(dplyr) library(tidyr) data(vehicles) e. Finally, for the years 1994, 1999, 2004, 2009, and 2014, find the average city mpg of midsize cars for each manufacturer for each year. Use tidyr to transform the resulting output so each manufacturer has one row, and five columns (a column for each year). I have included sample output for the first...
R Programming: Load the {ISLR} and {GGally} libraries. Load and attach the College{ISLR} data set. 1.2...
R Programming: Load the {ISLR} and {GGally} libraries. Load and attach the College{ISLR} data set. 1.2 Inspect the data with the ggpairs(){GGally} function, but do not run the ggpairs plots on all variables because it will take a very long time. Only include these variables in your ggpairs plot: “Outstate”,“S.F.Ratio”,“Private”,“PhD”,“Grad.Rate”. 1.3 Briefly answer: if we are interested in predicting out of state tuition (Outstate), can you tell from the plots if any of the other variables have a curvilinear relationship...
Use R statictical software. Load the ISLR package to get the Auto data set. Fit below...
Use R statictical software. Load the ISLR package to get the Auto data set. Fit below non-linear models to the Auto data set. We will treat horsepower as the predictor and mpg as the response. • Fit the cubic spline with 3 knots (25th percentile, 50th percentile, and 75th percentile of horsepower) • Fit the natural spline with 3 knots (25th percentile, 50th percentile, and 75th percentile of horsepower) • Fit the smoothing spline by choosing optimal lambda with cross-validation....
Assignment: Install and load the ggplot2 package. load the "diamonds" dataset RCode: install.packages("ggplot2") library(ggplot2) ?diamonds 1....
Assignment: Install and load the ggplot2 package. load the "diamonds" dataset RCode: install.packages("ggplot2") library(ggplot2) ?diamonds 1. Explore the dataset & state insights 2. Create plots for dataset 3: Provide summary of descriptive stats) 4. Run the regressions, research, Investigate & comment on R^2 & on regression plots - 1 line each. #=========================================== # DV = Price, IV or IVs = your choice # Can we create and compare models to predict "Price"? # Question- Investigate & comment on R^2 &...
Assignment: Install and load the ggplot2 package. load the "diamonds" dataset RCode: install.packages("ggplot2") library(ggplot2) ?diamonds 1....
Assignment: Install and load the ggplot2 package. load the "diamonds" dataset RCode: install.packages("ggplot2") library(ggplot2) ?diamonds 1. Explore the dataset & state insights 2. Create plots for dataset 3: Provide summary of descriptive stats) 4. Run the regressions, research, Investigate & comment on R^2 & on regression plots - 1 line each. #=========================================== # DV = Price, IV or IVs = your choice # Can we create and compare models to predict "Price"? # Question- Investigate & comment on R^2 &...
Assignment: Install and load the ggplot2 package. load the "diamonds" dataset RCode: install.packages("ggplot2") library(ggplot2) ?diamonds 1....
Assignment: Install and load the ggplot2 package. load the "diamonds" dataset RCode: install.packages("ggplot2") library(ggplot2) ?diamonds 1. Explore the dataset & state insights 2. Create plots for dataset 3: Provide summary of descriptive stats) 4. Run the regressions, research, Investigate & comment on R^2 & on regression plots - 1 line each. #=========================================== # DV = Price, IV or IVs = your choice # Can we create and compare models to predict "Price"? # Question- Investigate & comment on R^2 &...
Please do these questions in the R language 1. Load the cars dataset into R. It...
Please do these questions in the R language 1. Load the cars dataset into R. It is a built-in dataset. 2. Do an str() to determine the number of observations and variables. Enter your answer as a comment. 3. Plot speed on x axis and distance on y axis. 4. Find the correlation between speed and distance. What does the magnitude and sign indicate? Enter your answer as a comment. 5. Build a linear regression model with speed as the...
The dataset ’anorexia’ in the MASS package in R-Studio contains data for an anorexia study. In...
The dataset ’anorexia’ in the MASS package in R-Studio contains data for an anorexia study. In the study, three treatments (Treat) were applied to groups of young female anorexia patients, and their weights before (Prewt) and after (Postwt) treatment were recorded. The three treatments adminstered were no treatment (Cont), Cognitive Behavioural treatment (CBT), and family treatment (FT). Determine at the 5% significance level if there is a difference in mean weight gain between those receiving no treatment and those receiving...
The dataset ’anorexia’ in the MASS package in R-Studio contains data for an anorexia study. In...
The dataset ’anorexia’ in the MASS package in R-Studio contains data for an anorexia study. In the study, three treat- ments (Treat) were applied to groups of young female anorexia patients, and their weights before (Prewt) and after (Postwt) treatment were recorded. The three treatments adminstered were no treatment (Cont), Cognitive Behavioural treatment (CBT), and family treatment (FT). Determine at the 5% significance level if there is a difference in mean weight gain between those receiving no treatment and those...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT