Sofia Yaguana
September 2, 2017
This presentation explains the shiny application to predict the miles per gallon in the mtcars dataset.
The app shows a interactive regression for the variable mpg in the mtcars dataset.
The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973-74 models).
The model uses the variables with the strongest correlation with mpg: am, cyl, disp, hp, and wt.
\( mpg = 30.20 + 1.55am - 1.1cyl + 0.01disp - 0.02hp - 3.30wt \)
model <- lm(mpg ~ am + cyl + disp + hp + wt, data = mtcars)
summary(model)
Call:
lm(formula = mpg ~ am + cyl + disp + hp + wt, data = mtcars)
Residuals:
Min 1Q Median 3Q Max
-3.5952 -1.5864 -0.7157 1.2821 5.5725
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 38.20280 3.66910 10.412 9.08e-11 ***
am 1.55649 1.44054 1.080 0.28984
cyl -1.10638 0.67636 -1.636 0.11393
disp 0.01226 0.01171 1.047 0.30472
hp -0.02796 0.01392 -2.008 0.05510 .
wt -3.30262 1.13364 -2.913 0.00726 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.505 on 26 degrees of freedom
Multiple R-squared: 0.8551, Adjusted R-squared: 0.8273
F-statistic: 30.7 on 5 and 26 DF, p-value: 4.029e-10
The app takes five inputs: 1) transmission type, 2) number of cylinders 3) displacement, 4) gross horsepower, 5) weight.
Based on this inputs the model calculates the miles per gallon that a car would consume.
The server takes the input values and calculates the predicted value by using the regression model.
The appplication is in the following link:
https://sofiyag.shinyapps.io/assignment/
The ui.R and server.R codes and the regression model report are in the following link: