Executive Summary

This report investigates the relationship between miles per gallon (MPG) and transmission type using the mtcars dataset. Exploratory data analysis and regression models will be used to determine whether manual or automatic transmission is associated with better fuel economy and to quantify the difference in MPG, accounting for other vehicle characteristics where appropriate.

Exploratory Data Analysis

data(mtcars)

# Convert transmission type into a readable factor
mtcars$am <- factor(mtcars$am,
                    levels = c(0, 1),
                    labels = c("Automatic", "Manual"))

# Examine the dataset
dim(mtcars)
## [1] 32 11
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  : Factor w/ 2 levels "Automatic","Manual": 2 2 2 1 1 1 1 1 1 1 ...
##  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
##  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
summary(mtcars)
##       mpg             cyl             disp             hp       
##  Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0  
##  1st Qu.:15.43   1st Qu.:4.000   1st Qu.:120.8   1st Qu.: 96.5  
##  Median :19.20   Median :6.000   Median :196.3   Median :123.0  
##  Mean   :20.09   Mean   :6.188   Mean   :230.7   Mean   :146.7  
##  3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:326.0   3rd Qu.:180.0  
##  Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0  
##       drat             wt             qsec             vs        
##  Min.   :2.760   Min.   :1.513   Min.   :14.50   Min.   :0.0000  
##  1st Qu.:3.080   1st Qu.:2.581   1st Qu.:16.89   1st Qu.:0.0000  
##  Median :3.695   Median :3.325   Median :17.71   Median :0.0000  
##  Mean   :3.597   Mean   :3.217   Mean   :17.85   Mean   :0.4375  
##  3rd Qu.:3.920   3rd Qu.:3.610   3rd Qu.:18.90   3rd Qu.:1.0000  
##  Max.   :4.930   Max.   :5.424   Max.   :22.90   Max.   :1.0000  
##          am          gear            carb      
##  Automatic:19   Min.   :3.000   Min.   :1.000  
##  Manual   :13   1st Qu.:3.000   1st Qu.:2.000  
##                 Median :4.000   Median :2.000  
##                 Mean   :3.688   Mean   :2.812  
##                 3rd Qu.:4.000   3rd Qu.:4.000  
##                 Max.   :5.000   Max.   :8.000
# Compare MPG by transmission type
aggregate(mpg ~ am, data = mtcars, FUN = mean)
##          am      mpg
## 1 Automatic 17.14737
## 2    Manual 24.39231
aggregate(mpg ~ am, data = mtcars, FUN = sd)
##          am      mpg
## 1 Automatic 3.833966
## 2    Manual 6.166504

Visual Exploratory Analysis

# Boxplot comparing MPG across transmission types
boxplot(mpg ~ am, data = mtcars,
        col = c("lightblue", "lightgreen"),
        xlab = "Transmission Type",
        ylab = "Miles Per Gallon (MPG)",
        main = "MPG by Transmission Type")

# Scatter plot of MPG against vehicle weight
plot(mtcars$wt, mtcars$mpg,
     col = ifelse(mtcars$am == "Manual", "blue", "red"),
     pch = 19,
     xlab = "Weight (1000 lbs)",
     ylab = "Miles Per Gallon (MPG)",
     main = "MPG vs Vehicle Weight")
legend("topright",
       legend = c("Automatic", "Manual"),
       col = c("red", "blue"),
       pch = 19)

Regression Analysis

Model 1: MPG and Transmission Type

# Fit a simple linear regression model
model1 <- lm(mpg ~ am, data = mtcars)

# Display regression results
summary(model1)
## 
## Call:
## lm(formula = mpg ~ am, data = 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 ***
## amManual       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
# Calculate the 95% confidence intervals
confint(model1, level = 0.95)
##                2.5 %   97.5 %
## (Intercept) 14.85062 19.44411
## amManual     3.64151 10.84837

Model 2: Adjusting for Vehicle Weight

model2 <- lm(mpg ~ am + wt, data = mtcars)
summary(model2)
## 
## Call:
## lm(formula = mpg ~ am + wt, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.5295 -2.3619 -0.1317  1.4025  6.8782 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 37.32155    3.05464  12.218 5.84e-13 ***
## amManual    -0.02362    1.54565  -0.015    0.988    
## wt          -5.35281    0.78824  -6.791 1.87e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.098 on 29 degrees of freedom
## Multiple R-squared:  0.7528, Adjusted R-squared:  0.7358 
## F-statistic: 44.17 on 2 and 29 DF,  p-value: 1.579e-09
confint(model2)
##                 2.5 %    97.5 %
## (Intercept) 31.074114 43.568989
## amManual    -3.184815  3.137584
## wt          -6.964951 -3.740672

Model 3: Adjusting for Weight and Horsepower

model3 <- lm(mpg ~ am + wt + hp, data = mtcars)
summary(model3)
## 
## Call:
## lm(formula = mpg ~ am + wt + hp, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.4221 -1.7924 -0.3788  1.2249  5.5317 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 34.002875   2.642659  12.867 2.82e-13 ***
## amManual     2.083710   1.376420   1.514 0.141268    
## wt          -2.878575   0.904971  -3.181 0.003574 ** 
## hp          -0.037479   0.009605  -3.902 0.000546 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.538 on 28 degrees of freedom
## Multiple R-squared:  0.8399, Adjusted R-squared:  0.8227 
## F-statistic: 48.96 on 3 and 28 DF,  p-value: 2.908e-11
confint(model3)
##                   2.5 %      97.5 %
## (Intercept) 28.58963286 39.41611738
## amManual    -0.73575874  4.90317900
## wt          -4.73232353 -1.02482730
## hp          -0.05715454 -0.01780291

Model Comparison

AIC(model1, model2, model3)
##        df      AIC
## model1  3 196.4844
## model2  4 168.0292
## model3  5 156.1348
# Compare the models using adjusted R-squared
data.frame(
  Model = c("Transmission only",
            "Transmission + Weight",
            "Transmission + Weight + Horsepower"),
  Adjusted_R_squared = c(
    summary(model1)$adj.r.squared,
    summary(model2)$adj.r.squared,
    summary(model3)$adj.r.squared
  )
)
##                                Model Adjusted_R_squared
## 1                  Transmission only          0.3384589
## 2              Transmission + Weight          0.7357889
## 3 Transmission + Weight + Horsepower          0.8227357

Model Diagnostics

{r diagnostics, fig.width=8, fig.height=6} id="m8q2kp" # Diagnostic plots for Model 3 par(mfrow = c(2, 2)) plot(model3) par(mfrow = c(1, 1))

The four diagnostic plots help us check:

  1. Residuals vs Fitted: Looks for non-linearity and unequal error variance.
  2. Normal Q-Q: Checks whether residuals are approximately normally distributed.
  3. Scale-Location: Checks whether residual spread is reasonably constant.
  4. Residuals vs Leverage: Identifies potentially influential observations.

Statistical Inference and Model Selection

# Extract the adjusted transmission effect from Model 3
coef(summary(model3))
##                Estimate  Std. Error   t value     Pr(>|t|)
## (Intercept) 34.00287512 2.642659337 12.866916 2.824030e-13
## amManual     2.08371013 1.376420152  1.513862 1.412682e-01
## wt          -2.87857541 0.904970538 -3.180850 3.574031e-03
## hp          -0.03747873 0.009605422 -3.901830 5.464023e-04
# 95% confidence intervals for Model 3
confint(model3, level = 0.95)
##                   2.5 %      97.5 %
## (Intercept) 28.58963286 39.41611738
## amManual    -0.73575874  4.90317900
## wt          -4.73232353 -1.02482730
## hp          -0.05715454 -0.01780291
# Compare the nested regression models
anova(model1, model2, model3)
## Analysis of Variance Table
## 
## Model 1: mpg ~ am
## Model 2: mpg ~ am + wt
## Model 3: mpg ~ am + wt + hp
##   Res.Df    RSS Df Sum of Sq      F    Pr(>F)    
## 1     30 720.90                                  
## 2     29 278.32  1    442.58 68.734 5.071e-09 ***
## 3     28 180.29  1     98.03 15.224 0.0005464 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Executive Summary

This report investigates the relationship between miles per gallon (MPG) and transmission type using the 32-car mtcars dataset. Exploratory data analysis and three linear regression models were used to compare automatic and manual transmissions. The unadjusted model estimated that manual-transmission cars achieved approximately 7.25 MPG more than automatic cars (95% CI: 3.64 to 10.85). After adjusting for vehicle weight and horsepower, the estimated difference decreased to 2.08 MPG (95% CI: −0.74 to 4.90; p = 0.141). Thus, although manual cars had higher average MPG in the initial comparison, the adjusted analysis did not find a statistically significant transmission difference at the 5% level. Vehicle characteristics appear important when interpreting this association.

Conclusion

The exploratory analysis and simple regression model showed that manual-transmission cars had higher average fuel economy than automatic-transmission cars in the mtcars dataset. The estimated unadjusted difference was approximately 7.25 MPG, with a 95% confidence interval of 3.64 to 10.85 MPG.

However, after adjusting for vehicle weight and horsepower in Model 3, the estimated manual-transmission advantage decreased to 2.08 MPG. Its 95% confidence interval ranged from −0.74 to 4.90 MPG, and the p-value was 0.141. Therefore, the adjusted model did not provide sufficient evidence of a transmission-related MPG difference at the 5% significance level.

Model comparison showed that adding vehicle weight and then horsepower significantly improved model fit according to the nested-model ANOVA tests. The preferred model should also be evaluated using AIC, adjusted R-squared, and residual diagnostics.

In conclusion, manual cars had higher MPG in the unadjusted comparison, but the available data do not establish a statistically significant independent transmission effect after accounting for weight and horsepower. These results describe associations in a small dataset of 32 cars and do not establish causation.