Information Technology Reference
In-Depth Information
Discussion
When I started using R, the documentation said to use the lm function to perform linear
regression. So I did something like this, getting the output shown in Recipe 1.21 :
> lm(y ~ u + v + w)
Call:
lm(formula = y ~ u + v + w)
Coefficients:
(Intercept) u v w
1.4222 1.0359 0.9217 0.7261
I was so disappointed! The output was nothing compared to other statistics packages
such as SAS. Where is R 2 ? Where are the confidence intervals for the coefficients?
Where is the F statistic, its p -value, and the ANOVA table?
Of course, all that information is available—you just have to ask for it. Other statistics
systems dump everything and let you wade through it. R is more minimalist. It prints
a bare-bones output and lets you request what more you want.
The lm function returns a model object . You can save the object in a variable by using
the assignment operator ( <- ). This example assigns the object to the variable m :
> m <- lm(y ~ u + v + w)
From the model object, you can extract important information using specialized func-
tions. The most important function is summary :
> summary(m)
Call:
lm(formula = y ~ u + v + w)
Residuals:
Min 1Q Median 3Q Max
-3.3965 -0.9472 -0.4708 1.3730 3.1283
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.4222 1.4036 1.013 0.32029
u 1.0359 0.2811 3.685 0.00106 **
v 0.9217 0.3787 2.434 0.02211 *
w 0.7261 0.3652 1.988 0.05744 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.625 on 26 degrees of freedom
Multiple R-squared: 0.4981, Adjusted R-squared: 0.4402
F-statistic: 8.603 on 3 and 26 DF, p-value: 0.0003915
The summary shows the estimated coefficients. It shows the critical statistics, such as
R 2 , and the F statistic. It also shows an estimate of σ , the standard error of the residuals.
 
Search WWH ::




Custom Search