我正在尝试了解如何在泊松回归中从模拟数据中恢复模型估计。在StackExchange / CrossValidated(https://stats.stackexchange.com/questions/11096/how-to-interpret-coefficients-in-a-poisson-regression,https://stats.stackexchange.com/questions/128926/how-to-interpret-parameter-estimates-in-poisson-glm-results)上还有其他有关解释系数的类似文章,但我认为我的问题有所不同(尽管公认地相关)。我正在尝试重新建立已知关系,以便了解模型正在发生的事情。我在这里发布而不是CrossValidated,是因为我认为它的统计解释较少,而更多的是我如何通过代码获得已知/模拟的关系。
这里有一些与某些响应y
具有已知关系的模拟数据x
和resp
set.seed(707)
x<-rnorm(10000,mean=5,sd=1)
y<-rnorm(10000,mean=5,sd=1)
resp<-(0.5*x+0.7*y-0.1*x*y) # where I define some relationships
通过线性回归,非常简单:
summary(lm(resp~y+x+y:x))
输出显示x,y和相互作用之间的精确线性关系。
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.592e-14 1.927e-15 8.260e+00 <2e-16 ***
y 7.000e-01 3.795e-16 1.845e+15 <2e-16 ***
x 5.000e-01 3.800e-16 1.316e+15 <2e-16 ***
y:x -1.000e-01 7.489e-17 -1.335e+15 <2e-16 ***
现在,如果我对泊松回归感兴趣,我需要整数,我只是四舍五入,但保持预测变量和响应之间的关系:
resp<-round((0.5*x+0.7*y-0.1*x*y),0)
glm1<-glm(resp~y+x+y:x,family=poisson())
summary(glm1)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.419925 0.138906 3.023 0.0025 **
y 0.163919 0.026646 6.152 7.66e-10 ***
x 0.056689 0.027375 2.071 0.0384 *
y:x -0.011020 0.005261 -2.095 0.0362 *
据我了解,由于链接功能,人们需要对结果求幂。但是在这里,指数估计和截距+估计都不能使我回到原始值。
> exp(0.419925+0.163919)
[1] 1.792917
> exp(0.163919)
[1] 1.178119
我如何将这些值解释为与原始0.7*y
关系有关?
现在,如果将相同的线性方程式放入指数函数中,则可以直接获取值-无需使用exp()
:
resp<-round(exp(0.5*x+0.7*y-0.1*x*y),0)
summary(glm(resp~y+x+y:x,family=poisson()))
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.002970 0.045422 0.065 0.948
y 0.699539 0.008542 81.894 <2e-16 ***
x 0.499476 0.008912 56.047 <2e-16 ***
y:x -0.099922 0.001690 -59.121 <2e-16 ***
有人可以向我解释我在这里误解了什么,以及如何不首先如上所述使用exp()
函数就可以找到已知关系的原始值?
您忽略了默认情况下Poisson GLM使用日志链接(指数逆链接)的事实(或者,您并不是一直使用该信息)。您应该使用指数反向链接生成“数据”:
resp <- round(exp(0.5*x+0.7*y-0.1*x*y))
或使模型具有标识链接(family=poisson(link="identity")
)。 (我不推荐后者,因为它很少是一个明智的模型。)