Divyansh
October 2026
A Shiny app that predicts a car's fuel economy from weight, horsepower and transmission
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
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
lm().