Simple Linear Regression using R

 

Say we still want the regression model using displ to predict hwy (mpg data file). The R code is very simple:

> summary(lm(hwy ~ displ))
Call:
lm(formula = hwy ~ displ)

Residuals:
    Min      1Q  Median     3Q     Max 
-7.1039 -2.1646 -0.2242 2.0589 15.0105

Coefficients:
           Estimate Std. Error t value Pr(>|t|) 
(Intercept) 35.6977     0.7204   49.55   <2e-16 ***
displ       -3.5306     0.1945  -18.15   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.836 on 232 degrees of freedom
Multiple R-squared: 0.5868, Adjusted R-squared: 0.585 
F-statistic: 329.5 on 1 and 232 DF, p-value: < 2.2e-16

The result indicate there is a statistically significant relationship between hwy and displ (p-value < 2e-16).

 

See Also:

Do the same test in SAS

 

Leave a Reply

Your email address will not be published. Required fields are marked *