[R] Q: extracting data from lm
D. R. Evans
doc.evans at gmail.com
Fri Jul 27 23:52:19 CEST 2007
Warning: I am a complete newbie to R. I have read ISwR, but I am still
finding myself completely stuck on some simple concepts.
I have tried everything I can think of to solve this one, and finally
decided that enough was enough and I need a pointer to a solution.
I have the following summary from lm():
----
> summary(lm(nu1~nu4))
Call:
lm(formula = nu1 ~ nu4)
Residuals:
Min 1Q Median 3Q Max
-1572.62 -150.38 -21.70 168.57 2187.84
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 29.88739 43.68881 0.684 0.494
nu4 1.00036 0.01025 97.599 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 470.9 on 298 degrees of freedom
Multiple R-Squared: 0.9697, Adjusted R-squared: 0.9696
F-statistic: 9526 on 1 and 298 DF, p-value: < 2.2e-16
----
But I want to access some of these numbers programmatically. I finally
figured out that to get the estimate of the nu4 coefficient I need to do:
----
> lm(nu1~nu4)$coefficients[2]
nu4
1.000363
----
which to me as a long-time C++ programmer is close to black magic (I've
been programming since 1972; I have to say that R is unlike anything I've
ever seen, and it's far from trivial to get my head around some of it --
for example, how I could have known a priori that the above is the way to
get the nu4 coefficient is beyond me). Anyway, having figured out how to
get the estimate of the coefficient, I not-unnaturally wanted also to find
a way to access the std. error of the estimate (the value 0.01025 in the
summary). But I am completely mystified as to how to do it :-(
Any help gratefully (VERY gratefully) received, and I apologise if this is
a really, really stupid question and that the answer lies somewhere in some
documentation that I've obviously not properly taken on board.
More information about the R-help
mailing list