std.error of coefficients in lm
Date: Tue, 23 May 2000 16:21:55 +0200 From: Nina Lieske <nina.lieske at planet-interkom.de> X-Accept-Language: de,en To: r-help at stat.math.ethz.ch Subject: [R] std.error of coefficients in lm Dear All, sorry for bothering you with a simple (?) question. Is it possible to save the std.error of the estimated coefficients obtained by the summary.lm function? Something analogous to coef( )?
The trick here is to remember (know) that summary returns something that print.summary prints. So
example(lm) summary(lm.D9)
Call:
lm(formula = weight ~ group)
Residuals:
Min 1Q Median 3Q Max
-1.0710 -0.4937 0.0685 0.2462 1.3690
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.0320 0.2202 22.850 9.55e-15
groupTrt -0.3710 0.3114 -1.191 0.249
...
names(.Last.value)
[1] "call" "terms" "residuals" "coefficients" [5] "sigma" "df" "r.squared" "adj.r.squared" [9] "fstatistic" "cov.unscaled"
summary(lm.D9)$coeff
Estimate Std. Error t value Pr(>|t|) (Intercept) 5.032 0.2202177 22.850117 9.547918e-15 groupTrt -0.371 0.3114349 -1.191260 2.490232e-01
summary(lm.D9)$coeff[, "Std. Error"]
(Intercept) groupTrt 0.2202177 0.3114349 as required. You could write a little function to do this. More generally, the vcov function in the MASS package extracts variance-covariance matrices, so try library(MASS) sqrt(diag(vcov(lm.D9))) (Intercept) groupTrt 0.2202177 0.3114349 This works for lots of model classes, for example glm, nls, polr, multinom....
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._