从glm中提取标准错误

问题描述:

我做了glm,我只是想提取每个系数的标准错误。我在网上看到功能se.coef()但它不起作用,它返回"Error: could not find function "se.coef""从glm中提取标准错误

+0

可能有助于提供一些数据和示例代码。 – screechOwl 2011-12-13 21:01:16

您所追求的信息存储在由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()`明确计算错误? – 2011-12-14 12:40:44

+2

@ mindless.panda - AFAIK它们是由`summary.glm`直接计算出来的。如果你在控制台输入函数sans`()`,然后向下滚动约25行,你会看到它的计算位置。 – Chase 2011-12-14 15:12:55

另一种方式:

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

se.coef()实际上做的工作。但它不在基本包中:它位于{arm}包中:http://www.inside-r.org/packages/cran/arm/docs/se.ranef