On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...
CarProject
1. Motor Trend Analysis: Transmission effect on MPG
Slaw7
Data overview
Some basic exploratory data analysis of the mtcars data set.
We will look at a plot of Aautomatic/Manual transmission versus Miles Per Gallon.
library(ggplot2)
mpg_range <- range(0, mtcars$mpg)
par(mar=c(5.1,4.1,0.1,0.1))
plot(mpg~factor(am), data=mtcars,
xlab = "Transmission Type",
ylab="Miles Per Gallon (MPG)",
axes=FALSE, ann=FALSE)
axis(1, at=1:2, lab=c("Automatic","Manual"))
axis(2, las=1, at=5*0:mpg_range[2]); box()
It looks as though Munual Transmission cars have a better mpg than Automatic Transmission cars. However, we would like
to know more about other contributing factors.
cor(mtcars)[,c(1,9)]
## mpg am
## mpg 1.0000000 0.59983243
## cyl -0.8521620 -0.52260705
## disp -0.8475514 -0.59122704
## hp -0.7761684 -0.24320426
## drat 0.6811719 0.71271113
## wt -0.8676594 -0.69249526
## qsec 0.4186840 -0.22986086
## vs 0.6640389 0.16834512
## am 0.5998324 1.00000000
## gear 0.4802848 0.79405876
## carb -0.5509251 0.05753435
When looking at the correlation between the
variables of this data set, we see that four
variables have a correlation larger than 0.5
(in absolute value) with both “mpg” and
“am”. Those are: number of cylinders, dis-
placement, rear axle ratio (drat) and weight.
The appendix contains a visual of the rela-
tionships between these four variables with
both “mpg” and “am”.
Regression Models
A simple non-adjusted model. (Model 1)
Our first model will simply be based on the relationship between MPG and Type of Transmission without taking into
consideration any other variables.
fit1 <- lm(mpg~factor(am), data=mtcars)
summary(fit1)$coef[2,]
## Estimate Std. Error t value Pr(>|t|)
## 7.2449392713 1.7644216316 4.1061269831 0.0002850207
We estimate, not taking any other variables
into consideration, a manual transmission
will increase MPG by 7.24 mpg.
1
2. summary(fit1)$r.squared
## [1] 0.3597989
The R-squared value tells us that type of
Transmission alone is only accounting for
35.98% of the variance in MPG.
An adjusted model. (Model 2)
Next we will consider the effects of taking the four variables we identified above into account.
fit2 <- lm(mpg~factor(am)+factor(cyl)+disp+drat+wt,data=mtcars)
summary(fit2)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 34.796706680 6.70238133 5.1916931 2.271364e-05
## factor(am)1 0.261365828 1.53969659 0.1697515 8.665717e-01
## factor(cyl)6 -4.374626281 1.58014542 -2.7684960 1.045306e-02
## factor(cyl)8 -6.407637752 2.75347514 -2.3271094 2.835383e-02
## disp 0.001425009 0.01407923 0.1012136 9.201883e-01
## drat -0.255596739 1.56599820 -0.1632165 8.716602e-01
## wt -3.251684420 1.27325003 -2.5538459 1.713143e-02
Our adjusted estimate is that a manual trans-
mission will only increase MPG by 0.26 mpg.
But with a large p-value, we cannot conclude
that the Type of Transmission actually has
an effect on the mpg.
summary(fit2)$r.squared
## [1] 0.8377735
The R-squared value tells us that the five
variables used in our model, together account
for 83.78% of the variance in MPG.
Comparing the two models.
We will perform an anova test to compare the above models
anova(fit1,fit2)
## Analysis of Variance Table
##
## Model 1: mpg ~ factor(am)
## Model 2: mpg ~ factor(am) + factor(cyl) + disp + drat + wt
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 30 720.90
## 2 25 182.67 5 538.22 14.732 9.059e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
We conclude from the low p-value that we can reject the null hypothesis, and that the additional variables in the second
model are necessary to improve the prediction mpg.
Further analysis using a residual plot of the multivariate model is given in the Appendix section below.
Executive Summary
In this report we developed two models using the mtcars dataset, and used the results to answer the following questions.
Is an automatic or manual transmission better for MPG?
There is evidence to suggest that a manual transmission is better for MPG than an automatic, however, the difference between
the two may be minimal.
Quantify the MPG difference between automatic and manual transmissions.
Taking into account variables such as number of cylinders, displacement, rear axle ratio, and weight, the difference between
automatic and manual transmissions is estimated to be 0.26 mpg.
2