In this report we will be comparing the effect of having an automatic or manual transmition and the performance this has on MPG using a regression analysis. We will be using a dataset from the 1974 Motor Trend magazine to answer the following inquiries:
The conclusion for our analysis was: * Manual transmition is better than automatic transmition for MPG by a factor of 2.9358 MPG.
First we load the data. Then we will change the variable mtcars$am
from numeric value to a factor value. This variable is the one that says if the car transmition is either automatic or manual (0 = automatic, 1 = manual)
data(mtcars)
mtcars$am <- as.factor(mtcars$am)
levels(mtcars$am) <- c("Automatic", "Manual")
We will now perform some basic exploratory analysis to get to know more about the data.
summary(mtcars$mpg[mtcars$am=="Automatic"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.4 15.0 17.3 17.1 19.2 24.4
sd(mtcars$mpg[mtcars$am=="Automatic"])
## [1] 3.834
summary(mtcars$mpg[mtcars$am=="Manual"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 15.0 21.0 22.8 24.4 30.4 33.9
sd(mtcars$mpg[mtcars$am=="Manual"])
## [1] 6.167
We see that the standard deviation and mean from automatic and manual transmition and significantly different.
We will build a model using all the variables as predictors using the step
method in conjunction with lm
.
model <- step(lm(mpg ~ ., data=mtcars))
summary(model)
##
## Call:
## lm(formula = mpg ~ wt + qsec + am, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.481 -1.556 -0.726 1.411 4.661
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.618 6.960 1.38 0.17792
## wt -3.917 0.711 -5.51 7e-06 ***
## qsec 1.226 0.289 4.25 0.00022 ***
## amManual 2.936 1.411 2.08 0.04672 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.46 on 28 degrees of freedom
## Multiple R-squared: 0.85, Adjusted R-squared: 0.834
## F-statistic: 52.7 on 3 and 28 DF, p-value: 1.21e-11
By looking at the summary(model)
we can see that the intercept is at 9.6178 mpg and for the manual transmition we get 2.9358 which means that a car with manual transmition have an additional 2.9358 mpg compared with automatic transmition cars.
par(mfrow = c(2, 2))
plot(model)
boxplot(mtcars$mpg ~ mtcars$am, main='MPG for automatic and manual transmition', xlab='Transmission', ylab='MPG')