我可以报告一些关于
glm
和
offset()
的实验结果。从这个实验来看,你调用
predict
得到的结果似乎没有考虑到
offset
。相反,看起来需要使用
summary.glm
来实现这一目的。我从
?glm
中的第一个示例进行了一些修改(如果您提供数据,那么这将更加相关,因为我们可以更多地尝试使用"test"所需的newdata参数)。
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 + offset(1:9), family = poisson())
glm.D93d <- glm(counts ~ outcome + treatment , family = poisson())
> predict(glm.D93d, type="response")
1 2 3 4 5 6 7 8 9
21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 21.00000 13.33333 15.66667
> predict(glm.D93, type="response")
1 2 3 4 5 6 7 8 9
21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 21.00000 13.33333 15.66667
据我所知,只有在进行估计系数与空假设估计(通常为0)的比较以进行统计推断时,
offset
才会显现出来。这是由
summary.glm
完成的:
> summary(glm.D93)$coef
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.044522 0.1708987 11.963362 5.527764e-33
outcome2 -1.454255 0.2021708 -7.193203 6.328878e-13
outcome3 -2.292987 0.1927423 -11.896644 1.232021e-32
treatment2 -3.000000 0.2000000 -15.000000 7.341915e-51
treatment3 -6.000000 0.2000000 -30.000000 9.813361e-198
> summary(glm.D93d)$coef
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
偏移量仅更改参考水平(在这个混乱的示例中进行了相当奇怪的更改),而对$linear.predictors
和$fitted
与数据的拟合没有影响。我没有看到在glm中影响此项的评论,但在?lm
中有一条评论:“由offset指定的偏移量将不会包含在predict.lm的预测中,而由公式中的偏移项指定的偏移量将会包含在预测中。”我承认我从阅读?model.offset
中获得的见解很少。