Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This homework assignment will again consider consider the mtcars in R studio. En

ID: 3320244 • Letter: T

Question

This homework assignment will again consider consider the mtcars in R studio. Enter help(mtcars) for information about the variables in the data. Last week we considered modeling miles per gallon as depending linearly on the weight of the car (mpgwt). This week we will add more predictors and see if our predictions can be made more precise. In particular we will add the time it takes the car to go from a stop to complete a quarter mile (qsec) and an indicator of whether the car has an automatic or manual transmission (am, 0 for automatic, 1 for manual).

1.Add the independent variable am and fit the multiple linear regression model with 3 predictors (mpg wt+qsec+am).

2. Note the value of R2 and report how much it increased from the R2 of the model with only qsec and wt as predictors.

3. Suppose car A and car B weigh the same and can complete a quarter mile in the same amount of time. What would be the expected difference in miles per gallon if car A has an automatic transmission and car B has a manual transmission?

4. When testing the null hypothesis that type of transmission has no effect on mpg given wt and qsec at significance level = 0.05, what would you conclude?

5. Suppose car A weighs 3.5 thousand pounds, completes a quarter mile in 17 seconds and has an automatic transmission. Now suppose car B weighs 1.6 thousand pounds, completes a quarter mile in 15 seconds and has a manual transmission. Predict the difference in mpg between car A and car B.

Explanation / Answer

Please see the R code below

data(mtcars)
mtcars

## fit the regression

fit <- lm(mpg~ wt+qsec+am,data=mtcars)
summary(fit)

fit1 <- lm(mpg~ wt+qsec,data=mtcars)
summary(fit1)


## coefficients

fit$coefficients

The results are

summary(fit1)

Call:
lm(formula = mpg ~ wt + qsec, data = mtcars)

Residuals:
Min 1Q Median 3Q Max
-4.3962 -2.1431 -0.2129 1.4915 5.7486

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.7462 5.2521 3.760 0.000765 ***
wt -5.0480 0.4840 -10.430 2.52e-11 ***
qsec 0.9292 0.2650 3.506 0.001500 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.596 on 29 degrees of freedom
Multiple R-squared: 0.8264,   Adjusted R-squared: 0.8144
F-statistic: 69.03 on 2 and 29 DF, p-value: 9.395e-12

> summary(fit)

Call:
lm(formula = mpg ~ wt + qsec + am, data = mtcars)

Residuals:
Min 1Q Median 3Q Max
-3.4811 -1.5555 -0.7257 1.4110 4.6610

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.6178 6.9596 1.382 0.177915
wt -3.9165 0.7112 -5.507 6.95e-06 ***
qsec 1.2259 0.2887 4.247 0.000216 ***
am 2.9358 1.4109 2.081 0.046716 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.459 on 28 degrees of freedom
Multiple R-squared: 0.8497,   Adjusted R-squared: 0.8336
F-statistic: 52.75 on 3 and 28 DF, p-value: 1.21e-11

4. When testing the null hypothesis that type of transmission has no effect on mpg given wt and qsec at significance level = 0.05, what would you conclude?

summary(fit)

Call:
lm(formula = mpg ~ wt + qsec + am, data = mtcars)

Residuals:
Min 1Q Median 3Q Max
-3.4811 -1.5555 -0.7257 1.4110 4.6610

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.6178 6.9596 1.382 0.177915
wt -3.9165 0.7112 -5.507 6.95e-06 ***
qsec 1.2259 0.2887 4.247 0.000216 ***
am 2.9358 1.4109 2.081 0.046716 * we see that the p value is less than 0.05 , hence we conclude that am is statistically significant for the model
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.459 on 28 degrees of freedom
Multiple R-squared: 0.8497,   Adjusted R-squared: 0.8336
F-statistic: 52.75 on 3 and 28 DF, p-value: 1.21e-11

The regression equation is thus

mpg = 9.617 -3.91*wt +1.225*qsec + 2.93*am


we see that the r2 value without am is
Multiple R-squared: 0.8264

and including am is

Multiple R-squared: 0.8497

so there is an increase of 0.8497-0.8264 = 0.0233

The regression equation is thus

mpg = 9.617 -3.91*wt +1.225*qsec + 2.93*am


lets put the values for car a and car b

car a =

mpg = 9.617 -3.91*3.5 +1.225*17 + 2.93*1 = 19.68


car b =

mpg = 9.617 -3.91*1.6 +1.225*15 + 2.93*0 = 21.73

hence the difference is
21.73- 19.68 = 2.05

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote