2026-09-23

Explore fuel economy

A beginner-friendly Shiny application using R’s preloaded mtcars data.

A prediction should invite questions.

A number alone does not show what changed, why it changed, or how uncertain it is.

This application lets a learner change weight or horsepower and immediately see the model’s response.

Small by design

32 historical cars.

Two sliders.

Help inside the app.

Move a slider. See the result.

Try a simple comparison

Start with 3,000 lb and 110 horsepower.

Increase weight to 3,500 lb, holding horsepower fixed.

The prediction, selected point and explanatory text update automatically. Use Reset example, explore the in-app guide.

A reproducible prediction_1

fit <- lm(mpg ~ wt + hp,
          data = mtcars)
car <- data.frame(wt = 3000/1000, hp = 110)
result <- predict(fit, car,
  interval = "prediction", level = 0.95)
round(result, 1)
##    fit  lwr  upr
## 1 22.1 16.7 27.5

22.1 mpg Predicted fuel economy for 3,000 lb / 110 horsepower.

95% prediction range: 16.7 to 27.5 mpg.

A reproducible prediction_2

The code and numbers are regenerated when RStudio renders this presentation. The range describes one individual car, not a confidence interval for the mean.

Separate ui.R and server.R files make the calculation easy to inspect.