用R中Poisson GLM定义rstandard(标准化残差)

时间:2013-11-04 16:23:33

标签: r regression glm poisson

我想知道R在拟合泊松GLM时如何找到标准化残差或rstandard。我已经找到了this,但它并没有谈论标准化残差。所以这是一个简单的代码:

counts <- c(18,17,15,20,10,20,25,13,12)
x=rpois(9,1)
E=counts*10+rpois(9,2)
glm.D93 <- glm(counts ~ x+offset(log(E)), family=poisson)

现在我需要知道R如何计算:

> rstandard(glm.D93)
           1            2            3            4            5            6 
 0.018364902 -0.009725560  0.011933387 -0.026455659 -0.036635623 -0.002118836 
           7            8            9 
 0.036552236 -0.022033897  0.034771135

我在rstandard上使用了帮助,发现实际上有两种rstandard。一个基于“偏差”(默认),另一个基于“皮尔逊”残差。通过以下功能可以很容易地获得这两个功能:

> resid(glm.D93,type="dev")
> resid(glm.D93,type="pear")

我猜想要找到rstandard,我应该将两个残差除以第i个残差的标准偏差。谢谢。

1 个答案:

答案 0 :(得分:2)

很容易看到代码清楚显示您推断的功能。由于rstandard显然是通用的(大多数stats包函数是S3,你只需将类添加到“stem”函数名称:

> rstandard.glm
function (model, infl = influence(model, do.coef = FALSE), 
                 type = c("deviance", "pearson"), ...) 
{
    type <- match.arg(type)
    res <- switch(type, pearson = infl$pear.res, infl$dev.res)
    res <- res/sqrt(summary(model)$dispersion * (1 - infl$hat))
    res[is.infinite(res)] <- NaN
    res
}
相关问题