我已经运行了 Poisson Hurdle 模型,并且使用以下语法来对模型的零和计数部分产生部分效果。我目前使用的是
effects
软件包,它可能与 pscl
软件包不兼容。我也安装了 marginaleffects
软件包,但我不确定该软件包的正确功能是什么。
library(pscl)
library(effects)
data(quine, package = "MASS")
PoissonHurdle_model <- hurdle(Days ~ Eth + Sex + Age + Lrn,
data = quine, dist = "poisson")
partial_effects_zero <- allEffects(PoissonHurdle_model,component = "zero")
partial_effects_count <- allEffects(PoissonHurdle_model,component = "count")
我收到一条错误消息:
mod.matrix %*% scoef 中出现错误:参数不一致
我该如何解决这个问题?或者使用
marginaleffects
包计算效果的正确函数是什么?我知道我可以使用 margins 包,但它不适用于我正在使用的 R 版本。
我相信这些是您正在寻找的命令:
library(pscl)
library(marginaleffects)
data(quine, package = "MASS")
PoissonHurdle_model <- hurdle(
Days ~ Eth + Sex + Age + Lrn,
data = quine, dist = "poisson")
零分量的平均偏效应
avg_slopes(PoissonHurdle_model, type = "zero")
#;-)
#;-) Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#;-) Age mean(F1) - mean(F0) 0.000448 0.0607 0.00739 0.9941 0.0 -0.1185 0.1194
#;-) Age mean(F2) - mean(F0) 0.016649 0.0558 0.29852 0.7653 0.4 -0.0927 0.1260
#;-) Age mean(F3) - mean(F0) -0.003643 0.0665 -0.05479 0.9563 0.1 -0.1340 0.1267
#;-) Eth mean(N) - mean(A) -0.088072 0.0372 -2.36965 0.0178 5.8 -0.1609 -0.0152
#;-) Lrn mean(SL) - mean(AL) -0.011934 0.0485 -0.24601 0.8057 0.3 -0.1070 0.0831
#;-) Sex mean(M) - mean(F) -0.055396 0.0418 -1.32555 0.1850 2.4 -0.1373 0.0265
#;-)
#;-) Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted
#;-) Type: zero
响应分量的平均部分效应
avg_slopes(PoissonHurdle_model, type = "response")
#;-)
#;-) Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#;-) Age mean(F1) - mean(F0) -4.08 1.193 -3.42 <0.001 10.6 -6.416 -1.74
#;-) Age mean(F2) - mean(F0) 4.45 1.341 3.32 <0.001 10.1 1.822 7.08
#;-) Age mean(F3) - mean(F0) 8.08 1.811 4.46 <0.001 16.9 4.534 11.63
#;-) Eth mean(N) - mean(A) -8.73 0.901 -9.69 <0.001 71.3 -10.500 -6.97
#;-) Lrn mean(SL) - mean(AL) 5.67 1.244 4.56 <0.001 17.5 3.230 8.11
#;-) Sex mean(M) - mean(F) 2.32 0.957 2.42 0.0153 6.0 0.445 4.20
#;-)
#;-) Columns: term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted
#;-) Type: response
部分效应,将所有协变量保持为均值或众数
slopes(PoissonHurdle_model, type = "zero", newdata = "mean")
#;-)
#;-) Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#;-) Age F1 - F0 0.00104 0.0599 0.0174 0.986 0.0 -0.1163 0.1184
#;-) Age F2 - F0 0.01613 0.0551 0.2927 0.770 0.4 -0.0919 0.1242
#;-) Age F3 - F0 -0.00365 0.0654 -0.0559 0.955 0.1 -0.1318 0.1245
#;-) Eth N - A -0.05161 0.0506 -1.0203 0.308 1.7 -0.1508 0.0475
#;-) Lrn SL - AL -0.01408 0.0520 -0.2710 0.786 0.3 -0.1159 0.0878
#;-) Sex M - F -0.09043 0.0906 -0.9976 0.318 1.7 -0.2681 0.0872
#;-)
#;-) Columns: rowid, term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted, Eth, Sex, Age, Lrn, Days
#;-) Type: zero
部分效应,将所有协变量保持为均值或众数
slopes(PoissonHurdle_model, type = "response", newdata = "mean")
#;-)
#;-) Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#;-) Age F1 - F0 -2.506 0.780 -3.214 0.00131 9.6 -4.03 -0.978
#;-) Age F2 - F0 2.758 0.880 3.134 0.00172 9.2 1.03 4.482
#;-) Age F3 - F0 4.972 1.117 4.452 < 0.001 16.8 2.78 7.160
#;-) Eth N - A -4.255 0.556 -7.657 < 0.001 45.6 -5.34 -3.166
#;-) Lrn SL - AL 2.594 0.601 4.317 < 0.001 16.0 1.42 3.772
#;-) Sex M - F 0.612 0.858 0.713 0.47578 1.1 -1.07 2.295
#;-)
#;-) Columns: rowid, term, contrast, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, predicted_lo, predicted_hi, predicted, Eth, Sex, Age, Lrn, Days
#;-) Type: response