【问题标题】:Understanding glm$residuals and resid(glm)了解 glm$residuals 和 resid(glm)
【发布时间】:2011-02-01 15:43:22
【问题描述】:

你能告诉我 glm$residualsresid(glm) 返回什么,其中 glm 是一个准泊松对象。例如我将如何使用 glm$y 和 glm$linear.predictors 创建它们。

glm$residuals

     n missing  unique    Mean     .05     .10   .25  .50     .75     .90     .95

 37715   10042    2174 -0.2574 -2.7538 -2.2661 -1.4480 -0.4381  0.7542  1.9845  2.7749



lowest : -4.243 -3.552 -3.509 -3.481 -3.464
highest:  8.195  8.319  8.592  9.089  9.416

残渣(glm)

        n    missing     unique       Mean        .05        .10        .25
    37715          0       2048 -2.727e-10    -1.0000    -1.0000    -0.6276
      .50        .75        .90        .95
  -0.2080     0.4106     1.1766     1.7333

lowest : -1.0000 -0.8415 -0.8350 -0.8333 -0.8288
highest:  7.2491  7.6110  7.6486  7.9574 10.1932

【问题讨论】:

    标签: r glm


    【解决方案1】:

    调用 resid(model) 将默认为偏差残差,而 model$resid 将为您提供工作残差。由于链接功能,没有一个模型残差是什么的单一定义。有偏差、工作、部分、Pearson 和响应残差。因为这些仅依赖于均值结构(而不​​是方差),所以准泊松和泊松的残差具有相同的形式。您可以查看residuals.glm 函数了解详细信息,但这里是一个示例:

    counts <- c(18,17,15,20,10,20,25,13,12)
    outcome <- gl(3,1,9)
    treatment <- gl(3,3)
    glm.D93 <- glm(counts ~ outcome + treatment, family=quasipoisson())
    glm.D93$resid
    
    
    #working
    resid(glm.D93,type="working")
    (counts - glm.D93$fitted.values)/exp(glm.D93$linear)
    
    #deviance
    resid(glm.D93,type="dev")
    fit <- exp(glm.D93$linear)
    poisson.dev <- function (y, mu) 
        sqrt(2 * (y * log(ifelse(y == 0, 1, y/mu)) - (y - mu)))
    poisson.dev(counts,fit) * ifelse(counts > fit,1,-1)
    
    #response
    resid(glm.D93,type="resp")
    counts - fit
    
    #pearson
    resid(glm.D93,type="pear")
    (counts - fit)/sqrt(fit)
    

    【讨论】:

    • 这很棒。现在我只需要了解每种残差类型在进行回归诊断时最有用的时间。下面 Adam 提出的书籍推荐(Hardin 和 Hilbe 的“广义线性模型和扩展”)似乎很有帮助,还有其他建议吗?
    【解决方案2】:

    我对泊松和准泊松分布的了解不够,无法深入回答您所要求的问题(即使用模型将变量转换为残差的精确方程),但如果有任何混淆是由于使用了哪些残差类型以及为什么这两个命令给出不同的答案,这可能会有所帮助:

    resid() 默认为 R 中的“偏差”类型。但是,glm() 将不同的残差分配给 $residuals 向量。

    如果您使用的是准泊松族,glm() 将分配工作类型的残差,而 resid() 将偏差类型作为默认值。

    要试试这个,你可以使用:

    resid(glm,type="working")

    glm$残差

    这应该会给您相同的答案(至少,它在我使用的示例数据集上确实如此)。

    根据 R,工作残差是:“IWLS 拟合的最终迭代中的残差”

    如果您在 googlebooks 上查找书:“广义线性模型和扩展”(Hardin 和 Hilbe),您可以访问第 4.5 节,其中解释了各种类型的残差。

    【讨论】:

    • 对 Hardin 和 Hilbe 的书的很好参考!谢谢!
    猜你喜欢
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    相关资源
    最近更新 更多