I noticed when trying to back-transform predictions for my zero-truncated negative binomial model on the link scale to the response scale, the values are not the same:
set.seed(1)
data <- data.frame("x" = rep(1:5, 2), "y" = as.integer(runif(10)*100+1), "cat" = rep(c("a", "b"), each= 5))
mod <- glmmTMB::glmmTMB(y ~ x + (1|cat), data = data, family = truncated_nbinom2("log"))
new_data <- data.frame("x" = 1:3, "cat" = NA)
predict(mod, newdata = new_data, type = "response", re.form = NA)
exp(predict(mod, newdata = new_data, type = "link", re.form = NA))
Output:
> predict(mod, newdata = new_data, type = "response", re.form = NA)
[1] 79.08138 65.49391 54.24264
> exp(predict(mod, newdata = new_data, type = "link", re.form = NA))
[1] 79.07609 65.48655 54.23242
Why are they not the same? I specified the link function to be "log", then "exp" should invert it? The reason I don't directly predict to the response scale is that I want to calculate confidence intervals for an effect plot. Therefore I wanted to calculate the lower and upper confidence iterval using exp(fit +/- 2* se.fit)
.
Edit 1: This also happens when starting in a "fresh" environment:
Edit 2: This does not happen when using not truncated distributions, e.g. family = "poisson"
or family = nbinom2("log")
. But other truncated distributions, e.g. family = truncated_compois("log")
, also do not work.