Developing Data Products Project - MPG Predictor Application

Joshua Smith
August 18th, 2014

The MPG Predictor

This application can be used to predict the miles per gallon given the weight and horsepower of a vehicle.

The application is simple:

  • Enter the weight, in half-tons (the default value is the mean of the mtcars dataset)
  • Enter the horsepower (the default value is the mean of the mtcars dataset)
  • Click “submit” and view the results
  • Results are displayed graphically on two plots for comparison to mtcars values

The calculations were built using the mtcars dataset, so the application is intended for use on older vehicles.

The Regression Model

The MPG is predicted from a linear regression model calculated from the mtcars dataset.

fit <- lm(mpg ~ wt + hp, data = mtcars) #regression model
            Estimate Std. Error t value  Pr(>|t|)
(Intercept) 37.22727    1.59879  23.285 2.565e-20
wt          -3.87783    0.63273  -6.129 1.120e-06
hp          -0.03177    0.00903  -3.519 1.451e-03

The Formula

The previous code results in the following formula:

Let
\( \beta_0 \) = an intercept value, 32.22727
\( \beta_{wt} \) = the weight coefficient, -3.878
\( \beta_{hp} \) = the horsepower coefficient, -0.0318
\( X_{wt} \) = weight, in half-tons
\( X_{hp} \) = horsepower

Then

\( MPG = \beta_0 + \beta_{wt}X_{wt} + \beta_{hp}X_{hp} \)

Where MPG is the predicted miles per gallon

The application

To predict MPG, simply enter the desired weight, in half-tons and the horsepower, and click “submit”.

The function will calculate in the background and provide supporting graphics. For example:

If 2 half-tons is entered for “weight” and 120 is entered for horsepower, the application will report:

[1] 20.66

plot of chunk unnamed-chunk-4