Shoaib Haroon
July 2026
Fuel efficiency matters - but what drives it?
Yet most people have no quick way to estimate MPG from these specs without running R themselves.
This app solves that for any user, no R required.
The app takes three inputs from the user:
| Input | Widget | Range |
|---|---|---|
| Weight (1,000 lbs) | Slider | 1.5 - 5.5 |
| Horsepower | Slider | 52 - 335 |
| Cylinders | Radio buttons | 4 / 6 / 8 |
A linear regression model trained on R's built-in
mtcars dataset produces an instant MPG prediction.
The result updates reactively - no submit button needed.
model <- lm(mpg ~ wt + hp + cyl, data = mtcars)
round(summary(model)$coefficients, 3)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 38.752 1.787 21.687 0.000
wt -3.167 0.741 -4.276 0.000
hp -0.018 0.012 -1.519 0.140
cyl -0.942 0.551 -1.709 0.098
R-squared: 0.843 - the three predictors explain over 84% of MPG variance.
Each extra 1,000 lbs of weight costs roughly 3.17 MPG.
Live app: https://s8tlsi-shoaib-haroon.shinyapps.io/mpg-predictor/
Source code (GitHub): https://github.com/shoby0/mpg-predictor
Features at a glance: