Marc gave some good general advice, here are a couple more things that are more specific to your problem. Remember that most R functions return information, sometimes invisibly, but it is good to save the results. This includes the summary function (all the numbers that get printed out are also returned in an object). Try something like: fit <- lm(nu1~nu4) coef(fit)[2] sfit <- summary(fit) coef(sfit) se.nu4 <- coef(sfit)[2,2] of course some of us give into the temptation to go for terseness over readability and end up doing this like: se.nu4 <- coef(summary(lm(nu1~nu4)))[2,2] or se.nu4 <- summary(lm(nu1~nu4))$coefficients[2,2] hope this helps,
________________________________ From: [EMAIL PROTECTED] on behalf of D. R. Evans Sent: Fri 7/27/2007 3:52 PM To: r-help@stat.math.ethz.ch Subject: [R] Q: extracting data from lm 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. ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.