MPG Predictor

Divyansh
October 2026

A Shiny app that predicts a car's fuel economy from weight, horsepower and transmission

Why this app?

  • Fuel economy is the first thing buyers ask about.
  • Spec sheets list weight, power and gearbox, but not a clear MPG estimate.
  • MPG Predictor turns three simple inputs into an instant prediction with an honest uncertainty range.
  • No statistics background needed: two sliders, one radio button, one checkbox.

How it works (live R code)

The model is a linear regression fitted on the built-in mtcars data:

cars_df <- mtcars
cars_df$trans <- factor(cars_df$am, labels = c("Automatic", "Manual"))
fit <- lm(mpg ~ wt + hp + trans, data = cars_df)
round(summary(fit)$coefficients[, c(1, 4)], 4)
            Estimate Pr(>|t|)
(Intercept)  34.0029   0.0000
wt           -2.8786   0.0036
hp           -0.0375   0.0005
transManual   2.0837   0.1413

R-squared: 0.84

Example prediction

A 3,000 lb, 120 hp manual car:

new_car <- data.frame(wt = 3, hp = 120,
                      trans = factor("Manual", levels = levels(cars_df$trans)))
round(predict(fit, new_car, interval = "prediction"), 1)
  fit  lwr  upr
1  23 17.4 28.5

plot of chunk plot

Try it yourself