Your Name
October 28, 2026
A tiny Shiny app that predicts a car's fuel economy from its weight, horsepower and transmission.
We use the built-in mtcars dataset (32 cars) and a linear model.
fit <- lm(mpg ~ wt + hp + factor(am), data = mtcars)
round(summary(fit)$r.squared, 3)
[1] 0.84
round(coef(fit), 3)
(Intercept) wt hp factor(am)1
34.003 -2.879 -0.037 2.084
Weight and horsepower both reduce MPG; manual transmission adds a little.
A 3,000 lb, 120 hp manual car:
newcar <- data.frame(wt = 3, hp = 120, am = 1)
predict(fit, newcar, interval = "prediction")
fit lwr upr
1 22.95341 17.42961 28.47722
-figure/plot-1.png)