Question 1 A)

  1. If we want to determine if any transformations such as 𝑙𝑜𝑔(𝑥), √𝑥, or 𝑥2 are needed for a predictor, we can use a scatter plot between the predictor and the response variable (mpg) to identify any nonlinear patterns.
scatterplotMatrix(~mpg+disp+hp+drat+wt+qsec,data=mtcars)

From this plot, we can look for patterns that are not linear, such as curved relationships, or patterns where the spread of the data increases or decreases as the predictor value increases. These patterns may suggest that a transformation like 𝑙𝑜𝑔(𝑥), √𝑥, or 𝑥2 may be necessary to better model the relationship between the predictor and the response variable.

The scatter plot between mpg and disp, we can see that the relationship is curved, with a steep initial decline in mpg followed by a more gradual decline. This pattern suggests that a transformation like 𝑙𝑜𝑔(𝑥) or √𝑥 may be appropriate for the predictor disp.

Similarly, the scatter plot between mpg and wt shows a curved relationship, suggesting that a transformation like 𝑙𝑜𝑔(𝑥) or √𝑥 may be appropriate for the predictor wt.

In contrast, the scatter plot between mpg and qsec shows a relatively linear relationship, suggesting that a transformation may not be necessary for the predictor qsec.

## 
## Call:
## lm(formula = mpg ~ ., data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.4506 -1.6044 -0.1196  1.2193  4.6271 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) 12.30337   18.71788   0.657   0.5181  
## cyl         -0.11144    1.04502  -0.107   0.9161  
## disp         0.01334    0.01786   0.747   0.4635  
## hp          -0.02148    0.02177  -0.987   0.3350  
## drat         0.78711    1.63537   0.481   0.6353  
## wt          -3.71530    1.89441  -1.961   0.0633 .
## qsec         0.82104    0.73084   1.123   0.2739  
## vs           0.31776    2.10451   0.151   0.8814  
## am           2.52023    2.05665   1.225   0.2340  
## gear         0.65541    1.49326   0.439   0.6652  
## carb        -0.19942    0.82875  -0.241   0.8122  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.65 on 21 degrees of freedom
## Multiple R-squared:  0.869,  Adjusted R-squared:  0.8066 
## F-statistic: 13.93 on 10 and 21 DF,  p-value: 3.793e-07
##       cyl      disp        hp      drat        wt      qsec        vs        am 
## 15.373833 21.620241  9.832037  3.374620 15.164887  7.527958  4.965873  4.648487 
##      gear      carb 
##  5.357452  7.908747
## 
## Call:
## lm(formula = mpg ~ . - disp, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7863 -1.4055 -0.2635  1.2029  4.4753 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) 12.55052   18.52585   0.677   0.5052  
## cyl          0.09627    0.99715   0.097   0.9240  
## hp          -0.01295    0.01834  -0.706   0.4876  
## drat         0.92864    1.60794   0.578   0.5694  
## wt          -2.62694    1.19800  -2.193   0.0392 *
## qsec         0.66523    0.69335   0.959   0.3478  
## vs           0.16035    2.07277   0.077   0.9390  
## am           2.47882    2.03513   1.218   0.2361  
## gear         0.74300    1.47360   0.504   0.6191  
## carb        -0.61686    0.60566  -1.018   0.3195  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.623 on 22 degrees of freedom
## Multiple R-squared:  0.8655, Adjusted R-squared:  0.8105 
## F-statistic: 15.73 on 9 and 22 DF,  p-value: 1.183e-07
## 
## Call:
## lm(formula = mpg ~ . - disp - cyl, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8187 -1.3903 -0.3045  1.2269  4.5183 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) 13.80810   12.88582   1.072   0.2950  
## hp          -0.01225    0.01649  -0.743   0.4650  
## drat         0.88894    1.52061   0.585   0.5645  
## wt          -2.60968    1.15878  -2.252   0.0342 *
## qsec         0.63983    0.62752   1.020   0.3185  
## vs           0.08786    1.88992   0.046   0.9633  
## am           2.42418    1.91227   1.268   0.2176  
## gear         0.69390    1.35294   0.513   0.6129  
## carb        -0.61286    0.59109  -1.037   0.3106  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.566 on 23 degrees of freedom
## Multiple R-squared:  0.8655, Adjusted R-squared:  0.8187 
## F-statistic:  18.5 on 8 and 23 DF,  p-value: 2.627e-08

We can see that the Adjusted R-squared improves indeed when removing some predictors.

Question 2 A)

## 
## Call:
## lm(formula = Sales ~ Price + Urban + US, data = Carseats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9206 -1.6220 -0.0564  1.5786  7.0581 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 13.043469   0.651012  20.036  < 2e-16 ***
## Price       -0.054459   0.005242 -10.389  < 2e-16 ***
## UrbanYes    -0.021916   0.271650  -0.081    0.936    
## USYes        1.200573   0.259042   4.635 4.86e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.472 on 396 degrees of freedom
## Multiple R-squared:  0.2393, Adjusted R-squared:  0.2335 
## F-statistic: 41.52 on 3 and 396 DF,  p-value: < 2.2e-16
## (Intercept)       Price    UrbanYes       USYes 
## 13.04346894 -0.05445885 -0.02191615  1.20057270

The intercept coefficient (13.043) represents the estimated Sales when all other predictors are set to zero. In this case, it represents the estimated Sales when Price is zero (which doesn’t make sense) and Urban and US are both “No” (i.e., the store is in a rural area outside of the US).

The coefficient for Price (-0.054) indicates that, holding Urban and US constant, a one unit increase in Price is associated with a 0.054 unit decrease in Sales. This suggests that as the price of the car seats increase, the sales decrease.

The coefficient for UrbanYes (-0.022) indicates that, holding Price and US constant, stores located in urban areas have an average of 0.022 unit less Sales than stores located in rural areas.

The coefficient for USYes (-0.747) indicates that, holding Price and Urban constant, stores located in the US have an average of 0.747 unit less Sales than stores located outside the US.

  1. This is the models equation:

Sales = 13.043 - 0.054 * Price - 0.022 * UrbanYes - 0.747 * USYes

  1. We can see that there are three predictors: Price, Urban, and US. The p-value associated with each predictor gives us an indication of whether we can reject the null hypothesis of no relationship between that predictor and the response variable Sales.

Looking at the p-values, we can see that the p-value for Price is less than 0.05 (p-value < 2.2e-16), which suggests that we can reject the null hypothesis of no relationship between Price and Sales. In other words, Price is a statistically significant predictor of Sales.

On the other hand, the p-value for Urban is greater than 0.05 (p-value = 0.936), which suggests that we cannot reject the null hypothesis of no relationship between Urban and Sales. In other words, Urban is not a statistically significant predictor of Sales.

Similarly, the p-value for US is greater than 0.05 (p-value = 0.081), which suggests that we cannot reject the null hypothesis of no relationship between US and Sales. In other words, US is not a statistically significant predictor of Sales, although the p-value is close to the significance level of 0.05.

Therefore, we can reject the null hypothesis of no relationship between Price and Sales, but we cannot reject the null hypothesis of no relationship between Urban and Sales or between US and Sales.

## 
## Call:
## lm(formula = Sales ~ Price + US, data = Carseats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9269 -1.6286 -0.0574  1.5766  7.0515 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 13.03079    0.63098  20.652  < 2e-16 ***
## Price       -0.05448    0.00523 -10.416  < 2e-16 ***
## USYes        1.19964    0.25846   4.641 4.71e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.469 on 397 degrees of freedom
## Multiple R-squared:  0.2393, Adjusted R-squared:  0.2354 
## F-statistic: 62.43 on 2 and 397 DF,  p-value: < 2.2e-16
## [1] 0.2392754
## [1] 0.2392629

They both have similar R-squared values, with a similar amount of variance in the Sales variable.

##                   2.5 %      97.5 %
## (Intercept) 11.79032020 14.27126531
## Price       -0.06475984 -0.04419543
## USYes        0.69151957  1.70776632
  1. The plot doesn’t suggest outliers or high leverage observations.