Closed strengejacke closed 1 year ago
Seems related to https://github.com/easystats/modelbased/issues/217
Yes, they changed something in the truncated_poisson family. I found out following (copying my response from the related glmmTMB issue):
I think the problem is that for zero-inflation models, we assume that the predicted response is mu * (1 - zi_prob)
. We also compute predictions on the link-scale, then backtransform. However, this behaviour seems to have changed:
library(glmmTMB)
library(insight)
data("fish")
m1 <- glmmTMB(
count ~ child + camper + (1 | persons),
ziformula = ~ child + camper + (1 | persons),
data = fish,
family = truncated_poisson()
)
predict(m1, type = "response") |> head()
#> [1] 0.3747268 1.1037500 0.3747268 0.5692224 0.3747268 0.6854378
(link_inverse(m1)(predict(m1, type = "link")) * (1 - as.vector(predict(m1, type = "zprob")))) |> head()
#> [1] 0.2400130 0.9726394 0.2400130 0.4613930 0.2400130 0.6362097
linv <- family(m1)$linkinv
(linv(predict(m1, type = "link")) * (1 - as.vector(predict(m1, type = "zprob")))) |> head()
#> [1] 0.2400130 0.9726394 0.2400130 0.4613930 0.2400130 0.6362097
My question is, why is predicting the response no longer equal to predicting the count model on the link-scale, back-transform via link-inverse and multiply with the predicted zero-inflation-probability?
This issue also might affect the way we calculate CIs for truncated families (via the simulations)
CRAN found a revdep problem with the
insight
package (details below). @strengejacke, I think you are the maintainer. I need to be in an online meeting for most of today, but will try get to this in the evening if someone else hasn't already.Originally posted by @mebrooks in https://github.com/glmmTMB/glmmTMB/issues/873#issuecomment-1308426818