2026-11-23

The Problem & Solution

  • The Problem: Estimating how vehicle weight, horsepower, and transmission affect fuel economy can be unintuitive for car buyers.
  • The Solution: An interactive Shiny web application that predicts Miles Per Gallon (MPG) in real time.
  • Key Features:
    • Simple slider and radio-button controls
    • Instant linear regression predictions
    • Visual comparison against historical vehicles

Under the Hood: The Dataset

The application is powered by R’s built-in mtcars dataset (32 vehicles). Below is a summary of our predictor variables:

summary(mtcars[, c("mpg", "wt", "hp", "am")])
##       mpg              wt              hp              am        
##  Min.   :10.40   Min.   :1.513   Min.   : 52.0   Min.   :0.0000  
##  1st Qu.:15.43   1st Qu.:2.581   1st Qu.: 96.5   1st Qu.:0.0000  
##  Median :19.20   Median :3.325   Median :123.0   Median :0.0000  
##  Mean   :20.09   Mean   :3.217   Mean   :146.7   Mean   :0.4062  
##  3rd Qu.:22.80   3rd Qu.:3.610   3rd Qu.:180.0   3rd Qu.:1.0000  
##  Max.   :33.90   Max.   :5.424   Max.   :335.0   Max.   :1.0000

The Prediction Model

We use a multiple linear regression model predicting mpg from weight (wt), horsepower (hp), and transmission (am):

fit <- lm(mpg ~ wt + hp + factor(am), data = mtcars)
round(coef(fit), 3)
## (Intercept)          wt          hp factor(am)1 
##      34.003      -2.879      -0.037       2.084
  • Every 1,000 lbs of added weight reduces fuel efficiency by ~2.88 MPG.
  • Manual transmissions (am = 1) add ~2.08 MPG on average when holding weight and horsepower constant.

Visualizing the Relationship

Try It Yourself!