Fix overdispersion plot for glmmTMB and mixed models: correct residual scale and family variance formulas#913
Conversation
…MB models (#654)" Agent-Logs-Url: https://github.com/easystats/performance/sessions/1723c146-d8a3-4922-a155-33b39743440a Co-authored-by: strengejacke <26301769+strengejacke@users.noreply.github.com>
…7 threshold Agent-Logs-Url: https://github.com/easystats/performance/sessions/1723c146-d8a3-4922-a155-33b39743440a Co-authored-by: strengejacke <26301769+strengejacke@users.noreply.github.com>
|
@copilot I think the residuals using DHARMa are ok now, but I'm not sure about the variance. I refactored the code, and the variance is now calculated in
And you check and - if needed - update the calculation of the expected variance in |
…ily variance formulas Agent-Logs-Url: https://github.com/easystats/performance/sessions/bd0869ae-6edb-4383-a714-8408b4c798ea Co-authored-by: strengejacke <26301769+strengejacke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/easystats/performance/sessions/bd0869ae-6edb-4383-a714-8408b4c798ea Co-authored-by: strengejacke <26301769+strengejacke@users.noreply.github.com>
Done in commit
|


check_model()produced nonsensical overdispersion plots forglmmTMBmodels because of two compounding bugs: incorrect residual scaling and the wrong family variance formula being applied tonbinom1models.Changes
.model_diagnostic_overdispersion()(R/check_model_diagnostics.R): ForglmmTMBand mixed models (when DHARMa is available), uses DHARMa to obtain predictions and then computes response-scale residuals (observedResponse - fittedPredictedResponse):Res2= squared response-scale residuals — same scale as the family varianceVV= family-specific expected variance from.expected_variance()(e.g.μ(1+φ)for nbinom1)StdRes=residuals / sqrt(V)(Pearson-like standardized residuals for the type-2 plot).expected_variance()(R/check_model_diagnostics.R): Refactored to correctly dispatch onglmmTMBfamily names before the generalis_negbinbranch. Previously, the generalis_negbinbranch caughtnbinom1models and applied thenbinom2formula (μ(1 + μ/φ)). Formulas now match the glmmTMB documentation:nbinom1: V = μ(1 + φ)nbinom2: V = μ(1 + μ/φ)"zprob"(glmmTMB) or"zero"(other packages) correctlyRemoved
.new_diag_overdispersion()— unused prior attempt that mixed DHARMa residuals with the old variance scale, producing an inconsistent plotR/check_model.R: Pass...through to.model_diagnostic_overdispersion()so user-provided DHARMa args (e.g.iterations) propagate correctly