Closed AlpDYel closed 11 months ago
I might have figured out the issue (at least partially): If the random effects are discarded, I get the desired output (see example continued below)
#Predict with no SE
predict_merMod(mod_glmer,newdata=pred_data,re.form=~0,type="response",se.fit = T)->merMod_noRE
predict(mod_glmer,newdata=pred_data,re.form=~0,type="response")->predict_noRE
merMod_noRE$fit-predict_noRE # All 0!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#Predict with no SE
predict_merMod(mod_glmer,newdata=pred_data,re.form=~0,se.fit = T)->merMod_noRE_link
predict(mod_glmer,newdata=pred_data,re.form=~0)->predict_noRE_link
merMod_noRE_link$fit-predict_noRE_link #All 0!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
exp(merMod_noRE_link$fit) - merMod_noRE$fit #All 0!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Thank you for the reproducible report! I think I've gotten to the bottom of this; it appears to be a very legitimate bug. When SEs are requested, it is adding the random effects on the link scale to the already-transformed fixed effect predictions! When SEs aren't requested, this doesn't happen. And of course, when the user suppresses the random effects the bug won't manifest either.
Update inbound...
predict_merMod gives different answers from predict.merMod and itself when on response scale
I am using predict_merMod to get the prediction standard errors as described in http://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#predictions-andor-confidence-or-prediction-intervals-on-predictions ; however, in one model I got negative predicted probabilities and decided to dig further.
Based on my findings there is a major discrepancy when using predict_merMod(...,type="response") simply applying the inverse link function. In a reproducible example, I compared predict_merMod with type="link" and type="response" with predict.merMod with same spesifications. The results indicate that predict_merMod is off by some amount when it comes to predicting on the response scale. Am I mis-specifying something or is there an issue with response scale prediction?
As can be seen from the example, predict_merMod gives different predictions when on the response scale compared to not only predict.merMod but also predict_merMod in link scale with the inverse link applied.