R 中带有 pglm 包的伪 R2。(具有固定效应模型的泊松回归)

我需要根据使用 tidyr::extract 包进行的一些回归计算伪 R2,并修复泊松族和模型。

摘要中的伪R2在哪里?或者我如何计算它?

tidyr::extract(data,x,c('Parc','TipusBassa','Num'),'([A-Z]{3})([A-Z]?)([0-9]{2})',remove = FALSE)

#       x Parc TipusBassa Num
#1 GUIC01  GUI          C  01
#2  GUI02  GUI             02
fang567 回答:R 中带有 pglm 包的伪 R2。(具有固定效应模型的泊松回归)

对于伪 R2 计算,您需要空模型的对数似然或偏差。在上面带有 model = "within" 的面板 glm 中,不可能拟合空模型。所以你不能计算伪R2。

如果您使用 model = "random"model = "pooling",则可能:

library(pglm)
dat = data.frame(y = rpois(50,10),x = runif(50),x1 = rnorm(50),grp = factor(sample(1:2,nrow(dat),replace=TRUE)))
fit =  pglm(y ~ x+x1,data=dat,model="pooling",family="poisson",index="grp")

fit0 =  pglm(y ~ 1,index="grp")

所以使用最简单的 McFadden rsquared:

enter image description here

我们这样做:

pseudoR2 = as.numeric(1 - logLik(fit)/logLik(fit0))
本文链接:https://www.f2er.com/48039.html

大家都在问