Course Project: Shiny Application and Reproducible Pitch

Hari Prasad
Jan-14-2017

Project Objective: Predict Fuel Efficiency

Can you predict the Miles Per Gallon(Milage!?) if user provides follwing inputs?

  • Type of Transmission - 1 Manual, 0 Automatic
  • Quarter Mile Time in Seconds - 14 to 22 Second Range
  • Weight in 1000 lbs- 1 to 6 Range
  • Gross Horse Power - 50 - 400 Range

Exploratory Analysis

Data Description

The data to build model 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).

library("datasets")
data(mtcars)
attach(mtcars)
summary(mtcars)
      mpg             cyl             disp             hp       
 Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0  
 1st Qu.:15.43   1st Qu.:4.000   1st Qu.:120.8   1st Qu.: 96.5  
 Median :19.20   Median :6.000   Median :196.3   Median :123.0  
 Mean   :20.09   Mean   :6.188   Mean   :230.7   Mean   :146.7  
 3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:326.0   3rd Qu.:180.0  
 Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0  
      drat             wt             qsec             vs        
 Min.   :2.760   Min.   :1.513   Min.   :14.50   Min.   :0.0000  
 1st Qu.:3.080   1st Qu.:2.581   1st Qu.:16.89   1st Qu.:0.0000  
 Median :3.695   Median :3.325   Median :17.71   Median :0.0000  
 Mean   :3.597   Mean   :3.217   Mean   :17.85   Mean   :0.4375  
 3rd Qu.:3.920   3rd Qu.:3.610   3rd Qu.:18.90   3rd Qu.:1.0000  
 Max.   :4.930   Max.   :5.424   Max.   :22.90   Max.   :1.0000  
       am              gear            carb      
 Min.   :0.0000   Min.   :3.000   Min.   :1.000  
 1st Qu.:0.0000   1st Qu.:3.000   1st Qu.:2.000  
 Median :0.0000   Median :4.000   Median :2.000  
 Mean   :0.4062   Mean   :3.688   Mean   :2.812  
 3rd Qu.:1.0000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :1.0000   Max.   :5.000   Max.   :8.000  
#Converting the needed Factors based on observation in summary
mtcars$am<-as.factor(mtcars$am)
mtcars$cyl<-as.factor(mtcars$cyl)
mtcars$gear<-as.factor(mtcars$gear)
mtcars$carb<-as.factor(mtcars$carb)
mtcars$vs<-as.factor(mtcars$vs)
#Verifying again using Summary
mtcars<-mtcars
plot(mtcars)

plot of chunk unnamed-chunk-1

Model Selection & Final Equation

Let us build a simple regression model using given parameters for prediction. Plot of model pretty much agrees with regression model assumptions of homoscadacity and normal distribution. plot of chunk unnamed-chunk-2plot of chunk unnamed-chunk-2plot of chunk unnamed-chunk-2plot of chunk unnamed-chunk-2


Call:
lm(formula = mpg ~ wt + am + qsec + hp, data = mtcars)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.4975 -1.5902 -0.1122  1.1795  4.5404 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) 17.44019    9.31887   1.871  0.07215 . 
wt          -3.23810    0.88990  -3.639  0.00114 **
am1          2.92550    1.39715   2.094  0.04579 * 
qsec         0.81060    0.43887   1.847  0.07573 . 
hp          -0.01765    0.01415  -1.247  0.22309   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.435 on 27 degrees of freedom
Multiple R-squared:  0.8579,    Adjusted R-squared:  0.8368 
F-statistic: 40.74 on 4 and 27 DF,  p-value: 4.589e-11

This model explains the variability of 85.79% based multiple R Square. We have ended up with the regression equation:
mpg=17.44019+wt-3.23810+am-2.92550+qsec0.81060+hp-0.01765

Application Location and Links