【问题标题】:Extract standard errors from glm [duplicate]从glm中提取标准错误[重复]
【发布时间】:2012-01-19 17:32:55
【问题描述】:

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

【问题讨论】:

  • 可能有助于放置一些数据和示例代码。

标签: r extract glm standard-error


【解决方案1】:

您需要的信息存储在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 找到更多详细信息,但可能并非每次都需要该级别的详细信息,除非您

【讨论】:

  • 标准错误是否存储在glm.D93 对象中?我无法使用str() 关注它。还是summary() 明确计算错误?
  • @mindless.panda - AFAIK 它们直接由summary.glm 计算。如果您在控制台中输入函数而不使用 (),然后向下滚动大约 25 行,您将看到它的计算位置。
【解决方案2】:

另一种方式:

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

【讨论】:

  • 这很漂亮——纯粹而简单。
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 2012-06-21
    • 2020-03-31
    • 2014-07-13
    • 1970-01-01
    • 2013-01-11
    相关资源
    最近更新 更多