从glm中提取标准错误

时间:2011-12-13 20:57:05

标签: r extract glm standard-error

我做了一个glm,我只想提取每个系数的标准误差。我在互联网上看到了函数se.coef()但它不起作用,它返回 "Error: could not find function "se.coef""

3 个答案:

答案 0 :(得分:31)

您所关注的信息存储在coefficients返回的summary()对象中。你可以这样提取它: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 

查看names(summary(glm.D93)),快速查看返回的所有内容。如果您想查看正在进行的具体计算,可以通过签出summary.glm找到更多详细信息,但每次都不需要详细程度,除非您<3统计。

答案 1 :(得分:22)

另一种方式:

sqrt(diag(vcov(glm.D93)))

答案 2 :(得分:4)

se.coef()确实有效。但它不在基础包中:它在{arm}包中:http://www.inside-r.org/packages/cran/arm/docs/se.ranef