To answer both questions below:
.“Is an automatic or manual transmission better for MPG”
.“Quantify the MPG difference between automatic and manual transmissions”
We need to evaluate mpg and am (as described below):
– mpg: Miles/(US) gallon
– am: Transmission (0 = automatic, 1 = manual)
– n =32 observations
– source: Henderson and Velleman (1981), Building multiplt regression models interactively. Biometrics, 37, 391-411.
With that in mind we will analyse only these two variables and see if any conclusions will be enough.
tapply(mtcars$mpg, mtcars$am,summary)
## $`0`
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.40 14.95 17.30 17.15 19.20 24.40
##
## $`1`
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 15.00 21.00 22.80 24.39 30.40 33.90
model1 <- lm(mpg ~ as.factor(am), data=mtcars)
summary(model1)
##
## Call:
## lm(formula = mpg ~ as.factor(am), data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.3923 -3.0923 -0.2974 3.2439 9.5077
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.147 1.125 15.247 1.13e-15 ***
## as.factor(am)1 7.245 1.764 4.106 0.000285 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.902 on 30 degrees of freedom
## Multiple R-squared: 0.3598, Adjusted R-squared: 0.3385
## F-statistic: 16.86 on 1 and 30 DF, p-value: 0.000285
anova(model1)
## Analysis of Variance Table
##
## Response: mpg
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(am) 1 405.15 405.15 16.86 0.000285 ***
## Residuals 30 720.90 24.03
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model1.res = resid(model1)
plot(model1.res,
#ylab="Residuals",
#xlab="Transmissions",
main="Residuals")
abline(0, 0)
qqnorm(model1.res)
qqline(model1.res)
model2 <- lm(mpg ~ as.factor(am) - 1, data=mtcars)
summary(model2)
##
## Call:
## lm(formula = mpg ~ as.factor(am) - 1, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.3923 -3.0923 -0.2974 3.2439 9.5077
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## as.factor(am)0 17.147 1.125 15.25 1.13e-15 ***
## as.factor(am)1 24.392 1.360 17.94 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.902 on 30 degrees of freedom
## Multiple R-squared: 0.9487, Adjusted R-squared: 0.9452
## F-statistic: 277.2 on 2 and 30 DF, p-value: < 2.2e-16
anova(model2)
## Analysis of Variance Table
##
## Response: mpg
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(am) 2 13321.4 6660.7 277.18 < 2.2e-16 ***
## Residuals 30 720.9 24.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model2.res = resid(model2)
plot(model2.res,
#ylab="Residuals",
#xlab="Transmissions",
main="Residuals")
abline(0, 0)
qqnorm(model2.res)
qqline(model2.res)
As we can see both models have good residuals (diperse and normal) but the second one explain 94.5% of the mpg while the first one only 33% (R square).With a p-value less then 1% which means that for 100 cars less the 1 will have a mpg different then the one shown here.
Both models are able to show that manual transmission (1) in more effective because we can do more miles per gallon then with automatic ones (0): More specifically automatic transmissions do 7 miles per gallon less then manual:
Coefficients(model 1): Estimate
(Intercept) 17.147
as.factor(am)1 7.245
Coefficients (model 2): Estimate
as.factor(am)0 17.147 as.factor(am)1 24.392
Therefore manual transmissions are better for MPG and the difference between then are 7.25 miles per gallon more for manual.