Skip to content
Prev 5802 / 398506 Next

std.error of coefficients in lm

The trick here is to remember (know) that summary returns something
that print.summary prints.  So
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
...
[1] "call"          "terms"         "residuals"     "coefficients" 
 [5] "sigma"         "df"            "r.squared"     "adj.r.squared"
 [9] "fstatistic"    "cov.unscaled"
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
(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....