Add autocorrelation testing for simulated residuals and use simulated residuals for Poisson mixed models #860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses key issues raised in #595, #643, and #654 regarding the revision of
check_model()
functionality, focusing on improving diagnostic accuracy for generalized linear mixed models.Changes
1. Autocorrelation Testing for Simulated Residuals
Implements
check_autocorrelation()
method for simulated residuals objects, addressing the gap noted in #654:The new method uses
DHARMa::testTemporalAutocorrelation()
for robust temporal autocorrelation testing. Users can optionally provide atime
argument to specify temporal ordering if data are not already ordered by time.2. Simulated Residuals for Poisson Mixed Models
Previously, Poisson mixed models used Pearson residuals for overdispersion and zero-inflation tests, which could be inaccurate (see #464). This PR ensures these models now use simulated residuals, consistent with how zero-inflated and negative binomial models are handled:
check_overdispersion.merMod()
: Now includesinfo$is_poisson
in conditions for using simulated residualscheck_zeroinflation.default()
: Adds(model_info$is_mixed && model_info$is_poisson)
conditionThis change improves accuracy and maintains consistency across model types.
3. Documentation and Testing
Breaking Changes
The output structure for
check_overdispersion()
when applied to Poisson mixed models changes:Before:
After:
Rationale: Simulated residuals don't use chi-squared test statistics. This change provides more accurate dispersion estimates for Poisson mixed models.
Future Work
As noted in the original issues, the overdispersion diagnostic plots (called via
plot.check_overdisp()
) still use classical residuals. A TODO comment has been added to flag this for future improvement, which would require coordination with the see package for visualization updates.Closes #595
Related to #643, #654, #698
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.