March 26, 2026

Introduction & The Data

  • Objective: This project analyzes the already built in mtcars dataset in R to explore how the vehicle features relate to fuel efficiency.

  • The Data: Sourced from base R, mtcars contains data on 32 cars from the 1974 Motor Trend US magazine.

  • Key Variables of Interest:

    • mpg: Miles per gallon
    • wt: Weight (1000 lbs)
    • hp: Gross horsepower
    • cyl: # cylinders
    • am: Transmission type (Automatic or Manual)

Data Preparation

Here’s how I prepared and cleaned my data:

# converting variables to factors for cleaner plotting
data("mtcars")
mtcars <- mtcars %>%
  mutate(
    cyl = as.factor(cyl),
    am = factor(am, levels = c(0, 1), labels = c("Automatic", "Manual"))
  )

# quick preview of the dataset
head(mtcars[, c("mpg", "cyl", "wt", "hp", "am")], 3)
##                mpg cyl    wt  hp     am
## Mazda RX4     21.0   6 2.620 110 Manual
## Mazda RX4 Wag 21.0   6 2.875 110 Manual
## Datsun 710    22.8   4 2.320  93 Manual

Vehicle Distribution by Cylinders

The dataset is mostly composed of 8 cylinder vehicles, then 4 cylinder and 6 cylinder options.

Fuel Efficiency by Transmission

Manual transmissions in the dataset generally show a higher median fuel efficiency compared to automatics.

Weight vs. MPG (Interactive)

clear negative trend in this graph: as vehicle weight increases, miles per gallon (mpg) tends to decrease.

3D Performance Overview

The 3D graph shows that cars with both high weight and high horsepower tend to have the lowest fuel efficiency.

Statistical Analysis: Linear Regression

## 
## Call:
## lm(formula = mpg ~ wt + hp, data = mtcars)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.941 -1.600 -0.182  1.050  5.854 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 37.22727    1.59879  23.285  < 2e-16 ***
## wt          -3.87783    0.63273  -6.129 1.12e-06 ***
## hp          -0.03177    0.00903  -3.519  0.00145 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.593 on 29 degrees of freedom
## Multiple R-squared:  0.8268, Adjusted R-squared:  0.8148 
## F-statistic: 69.21 on 2 and 29 DF,  p-value: 9.109e-12

The regression output suggests that vehicle weight has a strong negative relationship with fuel efficiency. Horsepower also has a negative association, although weight appears to be the stronger predictor in this model.

Summary Statistics

# Descriptive statistics for the main numerical variables
summary(mtcars[, c("mpg", "wt", "hp")])
##       mpg              wt              hp       
##  Min.   :10.40   Min.   :1.513   Min.   : 52.0  
##  1st Qu.:15.43   1st Qu.:2.581   1st Qu.: 96.5  
##  Median :19.20   Median :3.325   Median :123.0  
##  Mean   :20.09   Mean   :3.217   Mean   :146.7  
##  3rd Qu.:22.80   3rd Qu.:3.610   3rd Qu.:180.0  
##  Max.   :33.90   Max.   :5.424   Max.   :335.0

These summary statistics show the spread of the main variables in the dataset. For example, MPG ranges from 10.4 to 33.9, showing a wide difference in fuel efficiency across the cars.

Key Findings & Statistical Summary

  • The visualizations show a clear negative relationship between vehicle weight and miles per gallon
  • Manual cars generally have higher fuel efficiency than automatic cars in this dataset I’m using
  • The 3D plot suggests that cars with both higher weight and higher horsepower tend to have the lowest mpg
  • The linear regression results support this pattern, with both wt and hp showing negative coefficients
  • Weight appears to be the stronger predictor of fuel efficiency in the regression model
  • The model explains a large portion of the variation in MPG, with an R squared of approx 0.83

Conclusion

  • Heavier cars tend to have lower fuel efficiency.
  • Manual cars generally show better MPG than automatics in this dataset.
  • Higher horsepower often appears alongside lower MPG, especially in heavier vehicles.
  • Overall, weight appears to be one of the strongest predictors of miles per gallon in the mtcars dataset.