Executive Summary :
This is an analysis of the ‘mtcars’ dataset to find out which type of transmission (Automatic/ Manual) is better for the MPG (miles per gallon) of a car, and quantification of the same. This report has been prepared as a ‘reproduceable research’ using R-markdown editor to generate PDF-output. Taking all variables into consideration, generally speaking, Manual-transmission have been found to be better than Automatic-transmission. Among all the regressors, the weight of the car has been found to be affecting most negatively the MPG - and more so for the Automatic-transmission car.
Note : the plots are at the end of the text (in the Appendix section).
Visualization, Analysis and model-fitting :
data(mtcars); require(stats, graphics)
str(mtcars)
## 'data.frame': 32 obs. of 11 variables:
## $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
## $ cyl : num 6 6 4 6 8 6 8 4 4 6 ...
## $ disp: num 160 160 108 258 360 ...
## $ hp : num 110 110 93 110 175 105 245 62 95 123 ...
## $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
## $ wt : num 2.62 2.88 2.32 3.21 3.44 ...
## $ qsec: num 16.5 17 18.6 19.4 17 ...
## $ vs : num 0 0 1 1 0 1 0 1 1 1 ...
## $ am : num 1 1 1 0 0 0 0 0 0 0 ...
## $ gear: num 4 4 4 3 3 3 3 4 4 4 ...
## $ carb: num 4 4 1 1 2 1 4 2 2 4 ...
m0 <- subset(mtcars, am == 0, c(1:8, 10, 11))
m1 <- subset(mtcars, am == 1, c(1:8, 10, 11))
Visualize the pair-plots of each of the datasets to have an idea about the correlations of the variables. Check the plots named “1. Automated Motors pair-plots” and “2. Manual Motors pair-plots” in Appendix section below.
From the plots drawn, it is clear that the two variables ‘vs’ and ‘gear’ have only two extreme values and no values in between , in each of the sub-datasets. Hence those two variables should not be considered for impact-analysis on ‘mpg’ and so we remove them from the datasets.
m0 <- m0[,-c(8,9)]
m1 <- m1[,-c(8,9)]
for (i in 1:8) { m0[,i] <- (m0[,i] - mean(m0[,i]))/sd(m0[,i]) }
for (i in 1:8) { m1[,i] <- (m1[,i] - mean(m1[,i]))/sd(m1[,i]) }
f0 <- lm(mpg ~ . -1, data = m0)
f1 <- lm(mpg ~ . -1, data = m1)
The residual plots are on the 5th page (in Appendix).
Quantifying the mpg-differences between the two transmission-types:
coef(f0)
## cyl disp hp drat wt qsec
## -0.04360172 -0.02347122 -0.30461632 0.39967752 -0.06690532 -0.04114192
## carb
## -0.47255863
The sum of the coefficients of f1 (i.e. model for Manual-transmission) is -0.13179, and the coefficients are:
coef(f1)
## cyl disp hp drat wt qsec
## 0.7946321 -1.0470468 0.6833974 0.1444945 -0.6541404 0.3427903
## carb
## -0.3959172
This means, for an unit increase in all the regressors, the mpg of the cars with automatic-transmission will decrease by 0.5526176 mpg, but that of the cars with manual-transmission will decrease by 0.13179 mpg.
Hence, manual-cars generally give better mpg, than the automatic-cars.
However, a closer look at the coeffieients suggest that if we remove the effect of the variable weight (wt), the sum of the coefficients for automatic-transmission is -0.4857123 and that for manual-transmission is 0.5223503, i.e., for the manual-transmission cars for every unit-increase in the regressors, the MPG will actually increase, whereas for automatic-cars, it will decrease.
Inferences :
From the analysis above, we can say that, generally speaking, cars with manual-transition are better than those with automatic-transmission.
Appendix : Plots :