Shreya Agarwal
Developing Data Products, Course Project
A Shiny app that predicts miles per gallon from weight, horsepower and transmission.
App: https://shreya-mpg-predictor.shinyapps.io/mpg-predictor/
Our solution: move three sliders/buttons and get an instant MPG prediction, a 95% prediction interval and a chart comparing your car with 32 real cars.
The server fits a linear regression on R's built-in mtcars data:
fit <- lm(mpg ~ wt + hp + am, data = mtcars)
round(coef(summary(fit))[, c("Estimate", "Pr(>|t|)")], 4)
Estimate Pr(>|t|)
(Intercept) 34.0029 0.0000
wt -2.8786 0.0036
hp -0.0375 0.0005
am 2.0837 0.1413
It explains 84% of the variation in MPG. Every extra 1000 lbs costs about 2.9 MPG.
A 3000 lb, 150 hp manual car:
predict(fit, data.frame(wt = 3, hp = 150, am = 1),
interval = "prediction")
fit lwr upr
1 21.82905 16.37024 27.28786
This is exactly the calculation server.R runs whenever a user moves a slider.
ui.R, server.R): https://github.com/shrxya1810/mpg-predictor