I have run a Poisson Hurdle model and I'm using the following syntax for the partial effects for the Zero and the Count part of the model. I'm using the effects
package at the moment which may not be compatible with pscl
package. I've installed the marginaleffects
package as well, but I'm not sure what the right function is for that package.
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")
I'm getting an error message:
Error in mod.matrix %*% scoef : non-conformable arguments
How do I resolve this? Or what would be the right function for calculating effects using the marginaleffects
package? I understand that I could use the margins package but it is not available for the R version that I'm using.
I believe these are the commands you are looking for:
library(pscl)
library(marginaleffects)
data(quine, package = "MASS")
PoissonHurdle_model <- hurdle(
Days ~ Eth + Sex + Age + Lrn,
data = quine, dist = "poisson")
Average Partial Effects for the Zero component
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
Average Partial Effects for the Response component
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
Partial Effects, holding all covariates to Mean or Mode
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
Partial Effects, holding all covariates to Mean or Mode
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