Pratham Nayak
October 27, 2026
A Shiny app that predicts a car's fuel economy from its weight, horsepower and transmission.
Our answer: a simple, interactive prediction tool built with R and Shiny.
We fit a linear regression on the built-in mtcars data:
data(mtcars)
mtcars$am <- factor(mtcars$am, labels = c("Automatic", "Manual"))
fit <- lm(mpg ~ wt + hp + am, data = mtcars)
round(summary(fit)$coefficients, 3)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 34.003 2.643 12.867 0.000
wt -2.879 0.905 -3.181 0.004
hp -0.037 0.010 -3.902 0.001
amManual 2.084 1.376 1.514 0.141
cat("R-squared:", round(summary(fit)$r.squared, 3))
R-squared: 0.84
Example prediction for a 3,000 lb, 120 hp manual car:
new <- data.frame(wt = 3, hp = 120,
am = factor("Manual", levels = c("Automatic", "Manual")))
round(predict(fit, new, interval = "prediction"), 1)
fit lwr upr
1 23 17.4 28.5