21

I did a glm and I just want to extract the standard errors of each coefficient. I saw on the internet the function se.coef() but it doesn't work, it returns "Error: could not find function "se.coef"".

zx8754
  • 52,746
  • 12
  • 114
  • 209
user1096592
  • 227
  • 1
  • 2
  • 3

3 Answers3

41

The information you're after is stored in the coefficients object returned by summary(). You can extract it thusly: summary(glm.D93)$coefficients[, 2]

#Example from ?glm
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
print(d.AD <- data.frame(treatment, outcome, counts))
glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())

#coefficients has the data of interest
> summary(glm.D93)$coefficients
                 Estimate Std. Error       z value     Pr(>|z|)
(Intercept)  3.044522e+00  0.1708987  1.781478e+01 5.426767e-71
outcome2    -4.542553e-01  0.2021708 -2.246889e+00 2.464711e-02
outcome3    -2.929871e-01  0.1927423 -1.520097e+00 1.284865e-01
treatment2   1.337909e-15  0.2000000  6.689547e-15 1.000000e+00
treatment3   1.421085e-15  0.2000000  7.105427e-15 1.000000e+00

#So extract the second column
> summary(glm.D93)$coefficients[, 2]
(Intercept)    outcome2    outcome3  treatment2  treatment3 
  0.1708987   0.2021708   0.1927423   0.2000000   0.2000000 

Take a look at names(summary(glm.D93)) for a quick review of everything that is returned. More details can be found by checking out summary.glm if you want to see the specific calculations that are going on, though that level of detail probably is not needed every time, unless you <3 statistics.

Chase
  • 67,710
  • 18
  • 144
  • 161
  • 1
    Are the standard errors stored within the `glm.D93` object? I couldn't eyeball it using `str()`. Or does `summary()` explicitly calculate the errors? – mindless.panda Dec 14 '11 at 12:40
  • 2
    @mindless.panda - AFAIK they are calculated directly by `summary.glm`. If you type the function into your console sans `()` and then scroll down about 25 lines, you'll see where it's calculated. – Chase Dec 14 '11 at 15:12
31

Another way:

sqrt(diag(vcov(glm.D93)))
Wojciech Sobala
  • 7,431
  • 2
  • 21
  • 27
6

se.coef() actually does work. But it's not in the base package: it's in the {arm} package: http://www.inside-r.org/packages/cran/arm/docs/se.ranef

Joel Chan
  • 61
  • 1
  • 2