This project consists into assess the relationship between a set of variables and miles per Gallon(MPG).
Mostly the Motor Trend is interested into the very nature of the answers to this specific questions:
*Is an automatic or manual transmission better for MPG?
*Quantify the MPG difference between automatic and manual transmissions.
Where we verified that transmission is not sufficient to explain the variations in MPG. We have accepted for this project accelleration, transmission and weight as the variables which would explain 84% variation of the gas mileage usage. Analysis shows that by using our best fit model to explain which variables are explaining the majority of the variation of MPG we were able to see that Manual would allow us to dirve with 2.97 more per gallon. (A.1)
Answer: Through a first and simplistic analysis, we visualized through the boxplot that the manual transmission definitely has higher mpg results, improving performance .The mean value of the gas mileage based on the transmission type is presented on the table presented below, showing that manual transmission yields a better performance than automatic. We have exclude the null hypothesis for a significance of 0.05% as per appendix A.4 by comparing the two means from the different transmissions.
## # A tibble: 2 x 2
## Transmission `mean(mpg)`
## <fctr> <dbl>
## 1 Automatic 17.14737
## 2 Manual 24.39231
A second conclusion embedded on the graphs above mentioned enabled us to see that other variables might present a significant role on the gas mileage use and therefore shall also be considered. Since the simplistisc model showed that transmission would only explain 35% of the variation of MPG (AppendiX A.2.)
We will test different models, where we will reduce the influence of this variables in our model in order to be able to reply if the transmission is the only variable to be held accountable or if other variables are indeed presenting a stronger association with gas mileage than transmission by itself. (i.e.MPG). ### 2. Models test(Linear Regression and Multivariable Regression)
## Analysis of Variance Table
##
## Model 1: mpg ~ Transmission
## Model 2: mpg ~ Transmission + qsec
## Model 3: mpg ~ Transmission + qsec + wt
## Model 4: mpg ~ Transmission + hp + qsec + wt
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 30 720.90
## 2 29 352.63 1 368.26 62.1186 1.791e-08 ***
## 3 28 169.29 1 183.35 30.9270 6.773e-06 ***
## 4 27 160.07 1 9.22 1.5551 0.2231
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
From the Anova analysis we were able to see that a model that would exclusively accept transmission as the only variable associated to the gas mileage would be a misinterpretation. A more complete model, where variables such as weight,acceleration and transmission are accounted, would present a stronger association with gas mileage usage (i.e.MPG). An F= 62.11 tell us that for a significance of of less than 0.1% chance that this large F ratio would happen if the null hypothesis was true, therefore we can conclude that model 2 would significantly be a better predictor of the gas mileage usage than considering only the transmission. In order to assess the overall fit of our model we have run another analysis to retrieve the adjusted R squared which allows us to infer that the model2, where transmission, acceleration and weight were chosen, it explains approximately 84% of the variation if we need to predict the gas mileage usage. In other words, We would need therefore to explain the changes on the mpg behavior by considering all this variables since they are largely responsible for their variation.(Appendix A.1.)
The residuals showed us that our model presents an unbiased and homoscedastic. Meaning The residuals average to zero in each thin verical strip and the standard deviation is the same all across the plot. We are able to see that for normality we might have some outliers but it does fall under normality assumption based on the QQ plot.(Appendix A.3.)
1.Is an automatic or manual transmission better for MPG?
It appears that manual transmission cars are better for MPG compared to automatic cars. However when modeled with confounding variables like qsec, HP and weight, the difference is not as significant as it seems in the beginning: a 84% of the mpg variation is explained by this same variables.
2.Quantify the MPG difference between automatic and manual transmissions
Analysis shows that by using our best fit model to explain which variables are explaining the majority of the variation of MPG we were able to see that Manual would allow us to dirve with 2.97 more per gallon. (A.1)
A.1 Summary of the model 2
##
## Call:
## lm(formula = mpg ~ Transmission + qsec + wt, data = new_mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.4811 -1.5555 -0.7257 1.4110 4.6610
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.6178 6.9596 1.382 0.177915
## TransmissionManual 2.9358 1.4109 2.081 0.046716 *
## qsec 1.2259 0.2887 4.247 0.000216 ***
## wt -3.9165 0.7112 -5.507 6.95e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.459 on 28 degrees of freedom
## Multiple R-squared: 0.8497, Adjusted R-squared: 0.8336
## F-statistic: 52.75 on 3 and 28 DF, p-value: 1.21e-11
A.2 Coefficients of the model
##
## Call:
## lm(formula = mpg ~ Transmission, data = new_mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.3923 -3.0923 -0.2974 3.2439 9.5077
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.147 1.125 15.247 1.13e-15 ***
## TransmissionManual 7.245 1.764 4.106 0.000285 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.902 on 30 degrees of freedom
## Multiple R-squared: 0.3598, Adjusted R-squared: 0.3385
## F-statistic: 16.86 on 1 and 30 DF, p-value: 0.000285
## (Intercept) TransmissionManual
## 17.147368 7.244939
A.3 Residual plots
A.4 Compare the means test Welch
#Null hypothesis
#The null hypothesis is that that automatic cars have an MPG 7.25 lower than manual cars.
auto<- new_mtcars[new_mtcars$Transmission== "Automatic",]
manual<-new_mtcars[new_mtcars$Transmission == "Manual",]
t.test(auto$mpg, manual$mpg)
##
## Welch Two Sample t-test
##
## data: auto$mpg and manual$mpg
## t = -3.7671, df = 18.332, p-value = 0.001374
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.280194 -3.209684
## sample estimates:
## mean of x mean of y
## 17.14737 24.39231