Use Pearson residuals for glmmTMB/MixMod heteroscedasticity plot - #460
Open
jbogomolovas2 wants to merge 1 commit into
Open
Use Pearson residuals for glmmTMB/MixMod heteroscedasticity plot#460jbogomolovas2 wants to merge 1 commit into
jbogomolovas2 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Companion to easystats/performance#927, which @strengejacke asked me to open.
The problem
plot.see_check_heteroscedasticity()carries its own copy of the branch fixedin performance#927, including a private copy of
.sigma_glmmTMB_nonmixed(). Soplot(check_heteroscedasticity(m))is affected the same way: forglmmTMBandMixModmodels the residuals are divided by a single scalar, which is onlycorrect when
V()does not depend onmu. For non-mixed binomial and Poissonmodels that scalar is
1, so no standardization happens and the panel bows forcorrectly specified models.
The full write-up, including the per-family table showing this affects nine of
eleven glmmTMB families rather than just binomial, is in performance#927.
The change
Same fix, ported. Try
residuals(type = "pearson"), keep the existingexpression as a fallback.
seehas no.safe()helper, so this usestryCatch()directly, matching the surrounding code.Effect
Correctly specified glmmTMB binomial fit (n = 600, size = 20). Left: patched.

Right: current behaviour, where the trend line humps in the middle purely
because binomial spread is largest near p = 0.5.
Also worth flagging,
.sigma_glmmTMB_nonmixed()in R/plot.check_heteroscedasticity.R readsglmmTMB renamed that parameter to
betadisp(glmmTMB commit 472ccbe0);performance's copy of this helper was updated, this one was not.
[does not partial-match, so the lookup returns NA,exp(NA)is NA, anddividing by it makes the whole panel NA. Nothing errors, so the surrounding
tryCatch does not catch it and the plot comes out silently blank.
Affects gaussian and Gamma glmmTMB fits. binomial/poisson/truncated_poisson
short-circuit to 1 before reaching that line.
Confirmed on glmmTMB 1.1.15:
Fix is the rename, in all three places in the switch(). Happy to PR it, but
noting it separately from # since it is a different failure mode.
Notes
performance#927.