This presentation describes the MPG Predictor Shiny App, which estimates miles per gallon based on engine cylinders and horsepower.
2025-11-28
This presentation describes the MPG Predictor Shiny App, which estimates miles per gallon based on engine cylinders and horsepower.
We use the built-in mtcars dataset.
## mpg cyl hp ## Min. :10.40 Min. :4.000 Min. : 52.0 ## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.: 96.5 ## Median :19.20 Median :6.000 Median :123.0 ## Mean :20.09 Mean :6.188 Mean :146.7 ## 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:180.0 ## Max. :33.90 Max. :8.000 Max. :335.0
model <- lm(mpg ~ cyl + hp, data = mtcars) summary(model)
## ## Call: ## lm(formula = mpg ~ cyl + hp, data = mtcars) ## ## Residuals: ## Min 1Q Median 3Q Max ## -4.4948 -2.4901 -0.1828 1.9777 7.2934 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 36.90833 2.19080 16.847 < 2e-16 *** ## cyl -2.26469 0.57589 -3.933 0.00048 *** ## hp -0.01912 0.01500 -1.275 0.21253 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 3.173 on 29 degrees of freedom ## Multiple R-squared: 0.7407, Adjusted R-squared: 0.7228 ## F-statistic: 41.42 on 2 and 29 DF, p-value: 3.162e-09
Users pick:
number of cylinders
horsepower
The app returns predicted MPG.
The app is deployed here: https://sleepystitch.shinyapps.io/mpg_predict/
Built in Shiny
Uses reactive prediction
Presentation created with RStudio Presenter
Code + app available on Rpubs and Github