This report analyzes the relationship between transmission type (automatic or manual) and miles per gallon (MPG) using the Motor Trend Car dataset. We address two key questions: whether transmission type affects MPG and quantifying the MPG difference between automatic and manual transmissions. Our analysis reveals significant differences in MPG between transmission types, with manual transmissions generally achieving higher MPG. We employ linear regression models to quantify this difference and provide insights into the factors influencing MPG.
Motor Trend seeks to understand how transmission type influences MPG in automobiles. We investigate this relationship using the MTCARS dataset, aiming to provide actionable insights for car enthusiasts and industry professionals.
We begin by exploring the dataset’s structure and summary statistics. The dataset contains 32 observations and 11 variables, including MPG, transmission type (am), and other car attributes. We visualize the distribution of MPG by transmission type and identify potential relationships between MPG and other variables.
| mpg | cyl | disp | hp | drat | |
|---|---|---|---|---|---|
| Min. :10.40 | Min. :4.000 | Min. : 71.1 | Min. : 52.0 | Min. :2.760 | |
| 1st Qu.:15.43 | 1st Qu.:4.000 | 1st Qu.:120.8 | 1st Qu.: 96.5 | 1st Qu.:3.080 | |
| Median :19.20 | Median :6.000 | Median :196.3 | Median :123.0 | Median :3.695 | |
| Mean :20.09 | Mean :6.188 | Mean :230.7 | Mean :146.7 | Mean :3.597 | |
| 3rd Qu.:22.80 | 3rd Qu.:8.000 | 3rd Qu.:326.0 | 3rd Qu.:180.0 | 3rd Qu.:3.920 | |
| Max. :33.90 | Max. :8.000 | Max. :472.0 | Max. :335.0 | Max. :4.930 |
| wt | qsec | vs | am | gear | |
|---|---|---|---|---|---|
| Min. :1.513 | Min. :14.50 | Min. :0.0000 | Min. :0.0000 | Min. :3.000 | |
| 1st Qu.:2.581 | 1st Qu.:16.89 | 1st Qu.:0.0000 | 1st Qu.:0.0000 | 1st Qu.:3.000 | |
| Median :3.325 | Median :17.71 | Median :0.0000 | Median :0.0000 | Median :4.000 | |
| Mean :3.217 | Mean :17.85 | Mean :0.4375 | Mean :0.4062 | Mean :3.688 | |
| 3rd Qu.:3.610 | 3rd Qu.:18.90 | 3rd Qu.:1.0000 | 3rd Qu.:1.0000 | 3rd Qu.:4.000 | |
| Max. :5.424 | Max. :22.90 | Max. :1.0000 | Max. :1.0000 | Max. :5.000 |
The provided summary of the mtcars dataset reveals key insights into the characteristics of the vehicles. Notably, the dataset showcases a range of values for attributes such as mileage per gallon (mpg), horsepower (hp), and weight (wt), indicating diversity in efficiency and performance. Additionally, the distribution of certain features, like the number of cylinders and transmission type, highlights prevalent trends such as the dominance of 6 or 8 cylinder engines and the prevalence of automatic transmissions. These statistics offer valuable insights into the composition and characteristics of the vehicles in the dataset, providing a foundation for further analysis and understanding of automotive trends and preferences.
# Mean of mpg for automatic transmission cars
mean(subset(mtcars, am == 0)$mpg)
## [1] 17.14737
# Mean of mpg for manual transmission cars
mean(subset(mtcars, am == 1)$mpg)
## [1] 24.39231
The visual analysis from both the Scatter Plot and Box Plot of MPG by Transmission Type suggests that manual transmission cars exhibit higher mileage, with a mean of 24.39 mpg compared to automatic transmission cars, which have a mean of 17.14 mpg. However, to substantiate these findings and ascertain their statistical validity, conducting a formal significance test is necessary.
Null Hypothesis (H0): There is no difference in the mean mileage between manual and automatic transmission cars. Alternative Hypothesis (H1): There is a difference in the mean mileage between manual and automatic transmission cars. Typically, a significance level (alpha) of 0.05 is chosen for hypothesis testing.
Since we are comparing the means of two independent groups (manual and automatic transmission cars), a two-sample t-test can be conducted to determine if there is a significant difference in mean mileage between the two groups.
# Subset data for manual and automatic transmission cars
mpg_manual <- mtcars$mpg[mtcars$am == 1]
mpg_auto <- mtcars$mpg[mtcars$am == 0]
# Perform two-sample t-test
t_test_result <- t.test(mpg_manual, mpg_auto)
# Print the result
print(t_test_result)
##
## Welch Two Sample t-test
##
## data: mpg_manual and mpg_auto
## 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:
## 3.209684 11.280194
## sample estimates:
## mean of x mean of y
## 24.39231 17.14737
The results of the two-sample t-test comparing the mean mileage between manual and automatic transmission cars in the mtcars dataset indicate a statistically significant difference (p-value = 0.001374) at the significance level of 0.05. This suggests that there is strong evidence to reject the null hypothesis, which implies that there is indeed a difference in mean mileage between the two transmission types. Specifically, manual transmission cars have a significantly higher mean mileage (24.39 mpg) compared to automatic transmission cars (17.14 mpg). This finding underscores the importance of transmission type in influencing fuel efficiency, with manual transmission cars demonstrating superior mileage performance.
model_am <- lm(mpg ~ factor(am), data = mtcars)
# Interpret coefficients
coefficients <- summary(model_am)$coefficients
interpretation <- ifelse(coefficients["factor(am)1", "Estimate"] > 0,
"Manual transmission cars have higher MPG compared to automatic transmission cars.",
"Automatic transmission cars have higher MPG compared to manual transmission cars.")
# Output interpretation
interpretation
## [1] "Manual transmission cars have higher MPG compared to automatic transmission cars."
Intercept (Automatic Transmission): The intercept indicates that the estimated MPG for automatic transmission cars (am=0) is approximately 17.147, with a standard error of 1.125.
Transmission Type (Manual vs. Automatic): The coefficient for
factor(am)1 (manual transmission) is approximately 7.245,
with a standard error of 1.764. This suggests that, on average, manual
transmission cars have approximately 7.245 units higher MPG compared to
automatic transmission cars.
fit_step <- step(lm(mpg ~ ., data = mtcars))
## Start: AIC=70.9
## mpg ~ cyl + disp + hp + drat + wt + qsec + vs + am + gear + carb
##
## Df Sum of Sq RSS AIC
## - cyl 1 0.0799 147.57 68.915
## - vs 1 0.1601 147.66 68.932
## - carb 1 0.4067 147.90 68.986
## - gear 1 1.3531 148.85 69.190
## - drat 1 1.6270 149.12 69.249
## - disp 1 3.9167 151.41 69.736
## - hp 1 6.8399 154.33 70.348
## - qsec 1 8.8641 156.36 70.765
## <none> 147.49 70.898
## - am 1 10.5467 158.04 71.108
## - wt 1 27.0144 174.51 74.280
##
## Step: AIC=68.92
## mpg ~ disp + hp + drat + wt + qsec + vs + am + gear + carb
##
## Df Sum of Sq RSS AIC
## - vs 1 0.2685 147.84 66.973
## - carb 1 0.5201 148.09 67.028
## - gear 1 1.8211 149.40 67.308
## - drat 1 1.9826 149.56 67.342
## - disp 1 3.9009 151.47 67.750
## - hp 1 7.3632 154.94 68.473
## <none> 147.57 68.915
## - qsec 1 10.0933 157.67 69.032
## - am 1 11.8359 159.41 69.384
## - wt 1 27.0280 174.60 72.297
##
## Step: AIC=66.97
## mpg ~ disp + hp + drat + wt + qsec + am + gear + carb
##
## Df Sum of Sq RSS AIC
## - carb 1 0.6855 148.53 65.121
## - gear 1 2.1437 149.99 65.434
## - drat 1 2.2139 150.06 65.449
## - disp 1 3.6467 151.49 65.753
## - hp 1 7.1060 154.95 66.475
## <none> 147.84 66.973
## - am 1 11.5694 159.41 67.384
## - qsec 1 15.6830 163.53 68.200
## - wt 1 27.3799 175.22 70.410
##
## Step: AIC=65.12
## mpg ~ disp + hp + drat + wt + qsec + am + gear
##
## Df Sum of Sq RSS AIC
## - gear 1 1.565 150.09 63.457
## - drat 1 1.932 150.46 63.535
## <none> 148.53 65.121
## - disp 1 10.110 158.64 65.229
## - am 1 12.323 160.85 65.672
## - hp 1 14.826 163.35 66.166
## - qsec 1 26.408 174.94 68.358
## - wt 1 69.127 217.66 75.350
##
## Step: AIC=63.46
## mpg ~ disp + hp + drat + wt + qsec + am
##
## Df Sum of Sq RSS AIC
## - drat 1 3.345 153.44 62.162
## - disp 1 8.545 158.64 63.229
## <none> 150.09 63.457
## - hp 1 13.285 163.38 64.171
## - am 1 20.036 170.13 65.466
## - qsec 1 25.574 175.67 66.491
## - wt 1 67.572 217.66 73.351
##
## Step: AIC=62.16
## mpg ~ disp + hp + wt + qsec + am
##
## Df Sum of Sq RSS AIC
## - disp 1 6.629 160.07 61.515
## <none> 153.44 62.162
## - hp 1 12.572 166.01 62.682
## - qsec 1 26.470 179.91 65.255
## - am 1 32.198 185.63 66.258
## - wt 1 69.043 222.48 72.051
##
## Step: AIC=61.52
## mpg ~ hp + wt + qsec + am
##
## Df Sum of Sq RSS AIC
## - hp 1 9.219 169.29 61.307
## <none> 160.07 61.515
## - qsec 1 20.225 180.29 63.323
## - am 1 25.993 186.06 64.331
## - wt 1 78.494 238.56 72.284
##
## Step: AIC=61.31
## mpg ~ wt + qsec + am
##
## Df Sum of Sq RSS AIC
## <none> 169.29 61.307
## - am 1 26.178 195.46 63.908
## - qsec 1 109.034 278.32 75.217
## - wt 1 183.347 352.63 82.790
# Summary of the selected model
summary(fit_step)
##
## Call:
## lm(formula = mpg ~ wt + qsec + am, data = 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
## wt -3.9165 0.7112 -5.507 6.95e-06 ***
## qsec 1.2259 0.2887 4.247 0.000216 ***
## am 2.9358 1.4109 2.081 0.046716 *
## ---
## 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
The stepwise regression analysis conducted on the mtcars dataset aimed to identify the most influential predictors of miles per gallon (MPG) among the available variables. Beginning with a full model containing all predictors, variables were systematically removed based on their contribution to model improvement, as measured by the Akaike Information Criterion (AIC). This process resulted in a final model comprising weight (‘wt’), quarter mile time (‘qsec’), and transmission type (‘am’). The coefficients of these predictors were found to be statistically significant, with weight negatively impacting MPG and quarter mile time positively impacting it. Notably, manual transmission cars exhibited significantly higher MPG compared to automatic transmission cars. The final model demonstrated a high Adjusted R-squared value of 0.834, indicating that approximately 83.4% of the variance in MPG could be explained by the selected predictors. Additionally, the F-statistic of 52.75, with a very low p-value (1.21e-11), underscored the model’s overall goodness of fit. These findings suggest that among the variables considered, weight, quarter mile time, and transmission type are the most significant determinants of MPG in the mtcars dataset, providing valuable insights for understanding and predicting fuel efficiency in automobiles.
Residual analysis is conducted to assess the adequacy of our models and to check for violations of regression assumptions. Diagnostic plots, such as residual vs. fitted plots and Q-Q plots, aid in evaluating model performance and identifying potential outliers or influential observations.
Both the residual plot and normal Q-Q plot provide evidence that the regression model is reasonably well-fitted to the data. The residuals exhibit randomness and approximate normality, supporting the validity of the model’s assumptions. However, it’s essential to note that there may be some minor deviations from normality in the extreme tails, which could be further investigated if necessary.
The analysis of the Motor Trend Car dataset revealed significant differences in miles per gallon (MPG) between automatic and manual transmission cars, with manual transmissions generally achieving higher MPG. This finding was supported by both exploratory data analysis and formal hypothesis testing using a two-sample t-test. Regression models further quantified this difference, indicating that manual transmission cars have approximately 7.245 units higher MPG compared to automatic transmission cars. Additionally, weight and quarter mile time were identified as significant predictors of MPG, alongside transmission type. The selected regression model exhibited a high Adjusted R-squared value of 0.834, indicating that approximately 83.4% of the variance in MPG could be explained by the selected predictors. Residual analysis and diagnostics supported the adequacy of the regression model, with residuals exhibiting randomness and approximate normality. Overall, these findings provide valuable insights for understanding and predicting fuel efficiency in vehicles, with transmission type, weight, and quarter mile time emerging as significant determinants of MPG.