Objectives of this project is to answer the following main questions
- “Is an automatic or manual transmission better for MPG?”
- “How different is the MPG between automatic manual transmission?”
Conclusions
- Manual transmissions are more fuel efficient than Automatics.
- The difference is that Manual transmissions are 80% (1.8) better than Automatics in fuel economy (MPG).
Load data and identify variables to factor using str().
data(mtcars)
str(mtcars)
Factor variables cyl,vs,gear,carb and including am to mtcarsdata.
mtcarsdata <- mtcars
mtcarsdata$cyl <- factor(mtcarsdata$cyl)
mtcarsdata$am <- factor(ifelse(mtcarsdata$am == 0, "Automatic", "Manual"))
mtcarsdata$vs <- factor(mtcarsdata$vs)
mtcarsdata$gear <- factor(mtcarsdata$gear)
mtcarsdata$carb <- factor(mtcarsdata$carb)
Plotted a boxplot of mpg per transmission type.
Manual transmission are more efficient than Automatic transmission.
Check Appendix - Figure1 (Barplot Transimission Type Comparison) - Page3
boxplot(mpg ~ am, data = mtcarsdata, notch=FALSE, xlab = "Transmission Type", ylab = "MPG",
main = "Transmission Comparison", varwidth = TRUE, col = c("orange","blue"))
legend("topleft", inset=.05, title="Transmissions",c("Automatic","Manual"),
fill=c("orange","blue"), horiz=TRUE)
Scatterplot to show mpg paired with all variables. Check Appendix - Figure2 (Scatterplot) - Page4
pairs(mpg ~ ., data = mtcarsdata,col="green")
Used step wise with multiple model methods ‘forward’ and ‘backward’ for modeling. Coefficients cyl (Cylinders),hp (Horsepower),wt (Weight) and am (Transmission Type)
fitmodel <- step(lm(data=mtcarsdata, mpg~.), direction="both")
summary(fitmodel)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 33.70832 2.60489 12.9404 7.733e-13
## cyl6 -3.03134 1.40728 -2.1540 4.068e-02
## cyl8 -2.16368 2.28425 -0.9472 3.523e-01
## hp -0.03211 0.01369 -2.3450 2.693e-02
## wt -2.49683 0.88559 -2.8194 9.081e-03
## amManual 1.80921 1.39630 1.2957 2.065e-01
t.test(mpg ~ am, data = mtcars)
##
## Welch Two Sample t-test
##
## data: mpg by am
## t = -3.767, df = 18.33, p-value = 0.001374
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.28 -3.21
## sample estimates:
## mean in group 0 mean in group 1
## 17.15 24.39
The Residuals vs. Fitted plot scattered opoints in the plot (independence).
The Normal Q-Q plot have points lie consistent within the line.
The Scale-Location plot consists of points laid out on scattered pattern.
There are some distinct points of interest (outliers) on the right.
Check Appendix - Figure3 (Residuals) - Page5
par(mfrow=c(2, 2))
plot(fitmodel)
The modeling shows that the best model includes the cyl6, cyl8 cyl, hp hp, wt wt, and amManual am variables (overall p-value<0.001).
The adjusted R-squared indicates that about 84% of the variance is explained by the final model. mpg increases having a Manual Transmission (by 1.8).
Manual transmission are more efficient than Automatic transmission.
The rate of change of the conditional mean mpg with respect to am is about 1.8.