从glm中提取标准误差

22

我进行了一次glm,我只想提取每个系数的标准误差。我在网上看到了se.coef()函数,但它不起作用,它返回"错误:找不到函数" se.coef ""


可能会有所帮助,可以提供一些数据和示例代码。 - screechOwl
3个回答

41

你需要的信息存储在summary()返回的coefficients对象中。你可以这样提取它: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,但是这种详细程度可能并非每次都需要,除非你热爱统计学。


1
标准误差是否存储在glm.D93对象中?我无法使用str()直接查看。或者summary()是否明确计算了误差? - mindless.panda
2
据我所知,它们是由summary.glm直接计算的。如果您在控制台中键入该函数但不包括(),然后向下滚动约25行,您将看到它的计算位置。 - Chase

31

另一种方法:

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

这很美丽 - 纯粹而简单。 - zx8754

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接