This months Motor Trend edition brings you an inside look at a comparison between Automatic and Manual Transmission cars in terms of Miles Per Galon. We first made a direct comparison between the two types and in the later part we compared the two transmission types based on Displacement, HP, Engine Type, etc.
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 ...
dim(mtcars)[1] ##Number of cars
## [1] 32
dim(mtcars[mtcars$am==0,])[1] ##Number of Automatic Transmission Cars
## [1] 19
dim(mtcars[mtcars$am==1,])[1] ##Number of Manual Transmission Cars
## [1] 13
For the given analysis we have 32 cars of which 19 cars have manual transmission and 13 have automatic transmission.
We build a linear model using mpg as the outcome and Transmission type (Manual or Automatic) as the predictor.
fit<-lm(mpg~as.factor(am),mtcars)
summary(fit)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.147368 1.124603 15.247492 1.133983e-15
## as.factor(am)1 7.244939 1.764422 4.106127 2.850207e-04
The coefficients we get are beta0= 17.15 and beta1= 7.25.
This shows that manual transmission cars have better mpg (by 7.25, mean=24.39). Therefore if we predict the Miles per Galon based on this prediction model, we get the following results:
predict(fit,data.frame(am=0)) ##For Automatic Transmission
## 1
## 17.14737
predict(fit,data.frame(am=1)) ##For Manual Transmission
## 1
## 24.39231
Based on our model, we see that mpg of manual transmission cars have greater mpg ie. 24.3923, whereas automatic transmission cars have 17.15.
It is clear that only transmission alone isn’t sufficient to make any conclusions. There are lots of other parameters to consider like number of cylinders, number of gears , weight, etc.
We individually explore the variables and see analyze their relation with mpg. We cannot use carb as a predictor as we dont have sufficient data. We see that we only have 1 car each in cases of 6 and 8 carb cars and there are no manual transmission cars with 3 carburators. Therefore, a comparison between Automatic and Manual Transmission cars on the basis of number of Carburators will result to errors in prediction.
Similarly we dont include gears in our prediction model as most of the automatic transmission cars are 3 geared and most of the manual transmission cars are 5 geared. Therefore a fair comparison cannot be made using number of gears for prediction. In the graph of MPG Vs Transmission Type for VS Type(Engine), we see that in each VS 0 or 1 engine type, the mpg of Manual Transmission cars is higher than those of the Automatic. Also, VS is also a good variable to be included in our prediction model.
In the graph of MPG Vs Weight, we can see that the MPG decreases with increase in weight. Also, Most of the Manual Transmission cars have lesser weight as compared to those of Automatic. Weight is thus included in our prediction model.
When we make a plot of MPG Vs Displacement and a plot of MPG Vs HP based on number of Cylinders, we see that most of the Manual Trnsmission cars have lower displacement, lower HP and are 4-Cylinder cars having higher MPG, whereas most of the Automatic transmission cars have higher displacement, higher HP and are 8-Cylinder cars having lower MPG.
The 3rd graph shows a somewhat linear relationship between Displacement and HP. Also, lower values of HP and Displacement have higher MPG values (darker is lesser).
-1. Lesser the Displacement, Higher is the MPG.
-2. Lesser the HP, Higher is the MPG.
-3. Lesser number of Cylinders imply lesser Displacement and HP. Therefore 4 Cylinder cars have lesser Displacement and HP.
-4. Lesser is the weight of the car, more is the MPG.
-5. VS 1 Engine cars have comparatively higher MPG.
-1. Most of the Manual Transmission cars have 4 Cylinders with lower Displacement, Weight and HP. Therefore their MPG is higher.
-2. Most of the Automatic Transmission cars are 8 Cylinder with low Displacement, Weight and HP. Therefore their MPG is higher.
-3. All the 6 Cylinder cars have fairly equal mpg around 18 to 21.
Using this model:
We create the multivariable regression model using the required variables.
l1<-lm(mpg~as.factor(am)+disp+hp+as.factor(cyl)+wt+as.factor(vs),mtcars)
The coefficients of the model are:
summary(l1)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.341720980 3.51903264 8.90634562 4.487003e-09
## as.factor(am)1 2.699154971 1.62818176 1.65777252 1.103789e-01
## disp 0.003996364 0.01270986 0.31443030 7.559114e-01
## hp -0.035107837 0.01412062 -2.48628166 2.026295e-02
## as.factor(cyl)6 -2.194219023 1.69157288 -1.29714720 2.069123e-01
## as.factor(cyl)8 -0.255243670 3.64192676 -0.07008479 9.447069e-01
## wt -2.610044217 1.17640731 -2.21865692 3.622055e-02
## as.factor(vs)1 1.986339954 1.79282988 1.10793555 2.788701e-01
We make predictions based on our new model with various possible settings. We consider the mean of the variables: HP, Displacement, Weight and plug-in the rest of the values. We observed that in every setting, the MPG of Manual Transmission cars is greater than Automatic Transmission cars.
Therefore we conclude that Manual Transmission cars have greater MPG than Automatic Transmission cars.
summary(l1)$sigma
## [1] 2.44174
Our data set consisted of 19 Automatic Transmission cars and 13 Manual Transmission cars. Therefore, a model that can tackle this difference in the number of cars of each transmission type has been created to get good results, by rejecting certain variables which were insufficiently provided for each transmission type car. Based on our prediction model, we found that Manual Transmission cars have greater MPG than Automatic Transmission cars.
Predicted MPG Values:
## Transmission VS Cylinder MPG
## 1 Automatic 0 4 18.72
## 2 Manual 0 4 21.42
## 3 Automatic 0 6 16.52
## 4 Manual 0 6 19.22
## 5 Automatic 0 8 18.46
## 6 Manual 0 8 21.16
## 7 Automatic 1 4 20.70
## 8 Manual 1 4 23.40
## 9 Automatic 1 6 18.51
## 10 Manual 1 6 21.21
## 11 Automatic 1 8 20.45
## 12 Manual 1 8 23.15