Car MPG Estimator

An easy way to explore fuel economy in a small car dataset

27 October 2026

The question

How do weight, horsepower, and transmission relate to miles per gallon?

The app lets you change all three and see an estimate straight away.

What the app does

Choose weight, horsepower, and automatic or manual transmission. A linear model fitted to R's mtcars data calculates the MPG estimate.

This R code is run when the presentation is rendered:

model <- lm(mpg ~ wt + hp + am, data = mtcars)
round(predict(model, newdata = data.frame(wt = 3, hp = 150, am = 0)), 1)
   1 
19.7 

See the data

The app places your estimate next to the original 32 cars. Heavier cars generally have lower MPG in this dataset.

plot of chunk unnamed-chunk-2

Try it

  1. Move the two sliders.
  2. Choose a transmission.
  3. Read the estimate and its prediction interval.

The app explains the controls on the page. Its 1973-74 car data make it useful for learning, not for predicting a modern car's official MPG.