The mtcars Linear Modeler Application

Derek Slone-Zhen
17 December 2014

Introduction - Fitting a Linear Model

The mtcars Linear Modeler is a fabuleous application for exploring your first linear regression model using Rs lm function from the builtin stats package.

R is a very powerful modelling environment. In just very small amount of code it is possbile to have R solve quite complex modeling problems. A simple linear regrassion model can be fitted just with:

fit <- lm(mpg ~ wt + am, data = mtcars)

And the reults shown with:

summary(fit)

Linear Model Output


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

Residuals:
    Min      1Q  Median      3Q     Max 
-4.5295 -2.3619 -0.1317  1.4025  6.8782 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 37.32155    3.05464  12.218 5.84e-13 ***
wt          -5.35281    0.78824  -6.791 1.87e-07 ***
am          -0.02362    1.54565  -0.015    0.988    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.098 on 29 degrees of freedom
Multiple R-squared:  0.7528,    Adjusted R-squared:  0.7358 
F-statistic: 44.17 on 2 and 29 DF,  p-value: 1.579e-09

And Graphs

  • And the “goodness” of the fit can be determined through diagnostic plots:
plot(fit,1); plot(fit,2); 

plot of chunk plot plot of chunk plot

But Why an Interactive Application For This?

Because, with an interactive application, you can focus you attention on the changes that happen to the numbers or the graphs as you add or remove explanatory variables from the fit.

The eye reacts well to these “moving images” and picks up on the changes in the images much better than if it had to flick focus between two different graphs or tables.

This app will certainly make it quicker for you to complete your factor selection processes.

Go to the app site NOW!!

http://dereksz.shinyapps.io/mtcars-Linear-Modeler/