Besides personal preferences in comfort or driving styles, automatic and manual transmission deliver different performance to cars. We will create exploratory data analysis to understand how much the transmission affects the mpg and if this is influenced when other variables are taken into account. We are testing the hypothesis that both cylinders and horse power mean efficiency for the mpg , thus will help us further understand how much does the transmission affect mpgs.
________________________________________________________
We are reading data from the mtcars data, which includes a data frame with 32 observations on 11 variables. The main variables we will take into account are: am( Transmission (0 = automatic, 1 = manual)), hp( Gross horsepower), mpg (Miles/(US) gallon) & cyl (Number of cylinders) In an exploratory data analysis we plotted the different variables to get a rough understanding of their behaviour. Through this the manual transmission outperforms the automatic transmission, with a mean of 24.3 vs a 17.14 in the case of the automatic transmission. ( Refer to figure 1 in appendix.)
We will run a series of regressions to see if it is really the manual transmission outperforming the automatic transmission when we include other variables besides the transmission
In the first regression just with mpg & am , we see that the R-squared is low , therefore is not that significant for the MPG, while both the values for intercept and am are what we already know in terms of the manual tranmission being better by 7.24 mpgs
When we add cylinders into the mix as well as horse power to indentify a better performance in the regression. Through these results we have a higher R squared, this time it is significant with .82 and both the standard error and the degrees of freedom have gone lower. When we add cylinders and horsepower the tranmission is no longer 7.24mpgs better, and its now just 4.1579 mpgs better, thus there is less difference and higher significance in the results.
#Fit Regression
fit <- lm(mpg ~ factor(am), mtcars)
summary(fit)
##
## Call:
## lm(formula = mpg ~ factor(am), data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.392 -3.092 -0.297 3.244 9.508
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.15 1.12 15.25 1.1e-15 ***
## factor(am)1 7.24 1.76 4.11 0.00029 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.9 on 30 degrees of freedom
## Multiple R-squared: 0.36, Adjusted R-squared: 0.338
## F-statistic: 16.9 on 1 and 30 DF, p-value: 0.000285
fit2 <- lm(mpg ~ factor(am) + factor(cyl) + hp, mtcars)
summary(fit2)
##
## Call:
## lm(formula = mpg ~ factor(am) + factor(cyl) + hp, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.231 -1.535 -0.141 1.408 5.322
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 27.2959 1.4239 19.17 <2e-16 ***
## factor(am)1 4.1579 1.2566 3.31 0.0027 **
## factor(cyl)6 -3.9246 1.5375 -2.55 0.0167 *
## factor(cyl)8 -3.5334 2.5028 -1.41 0.1694
## hp -0.0442 0.0146 -3.04 0.0053 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.7 on 27 degrees of freedom
## Multiple R-squared: 0.825, Adjusted R-squared: 0.799
## F-statistic: 31.8 on 4 and 27 DF, p-value: 7.4e-10
We will plot the residual graphs to get a better understanding of how the new regression that takes into account more variables behaves.
Residuals from the 2nd model generates a slightly better fit to the line than the 1st one, there are no apparent outliers
“Is an automatic or manual transmission better for MPG”
When assesing just the performance of mpg vs transmission, manual transmission performs better by over 7 mpg. A car needs more variables to explain its performance, based in the idea that horse power and cylinders in the car might influence the efficiency of the mpg, we can now say that horse power, cylinders and tranmission explain about 82% of the performance of the mpg in a car.
Taking this factors into account, the manual transmission outperforms the automatic tranmission by 4.1579mpg
Figure 1
## The following objects are masked from mtcars (position 3):
##
## am, carb, cyl, disp, drat, gear, hp, mpg, qsec, vs, wt