Description
I came across a bug when predicting from a model with a smooth term.
The issue is that if I try to predict without the random effect terms, I get different results (at time widely different results).
To reproduce, using the example from the help file –
data("Nile")
ndat <- data.frame(time = c(time(Nile)), val = c(Nile))
sm1 <- glmmTMB(val ~ s(time), data = ndat,
REML = TRUE, start = list(theta = 5))
plot(val ~ time, data = ndat)
lines(ndat$time, predict(sm1))
lines(ndat$time, predict(sm1, re.form=NA), col='red')
In this case, the model has no random effect term, and so the two predictions should overlap but they don’t. The difference is not incredibly large here but in other datasets it can be all over the place. The version without the re.form=NA seems to be correct one.
I have similar results with models including random effects (of course here re.form=NA should be irrelevant).
I can get the correct result by using predict(x) and then remove the random effects by hand with something like (fm is the fitted model, r has my data, V1 is the random effect feature) –
p = predict(fm)
r = ranef(fm)$cond$V1;
p2 = p-r[x$V1,]
but that’s not ideal.