-
-
Notifications
You must be signed in to change notification settings - Fork 49
Use Pearson residuals for glmmTMB/MixMod heteroscedasticity plot #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,12 +39,25 @@ plot.see_check_heteroscedasticity <- function( | |
| if (inherits(model, "merMod")) { | ||
| stats::residuals(model, scaled = TRUE) | ||
| } else if (inherits(model, c("glmmTMB", "MixMod"))) { | ||
| sig <- if (faminfo$is_mixed) { | ||
| sqrt(insight::get_variance_residual(model)) | ||
| ## Pearson residuals are scaled by the family's variance function V(mu_i), | ||
| ## which varies across observations. The fallback below divides by a single | ||
| ## scalar, which is only correct when V() does not depend on mu (e.g. | ||
| ## gaussian). For non-mixed binomial/poisson models `.sigma_glmmTMB_nonmixed()` | ||
| ## returns 1, i.e. no standardization at all. | ||
| r_pearson <- tryCatch( | ||
| stats::residuals(model, type = "pearson"), | ||
| error = function(e) NULL | ||
| ) | ||
| if (is.null(r_pearson) || all(is.na(r_pearson))) { | ||
| sig <- if (faminfo$is_mixed) { | ||
| sqrt(insight::get_variance_residual(model)) | ||
| } else { | ||
| .sigma_glmmTMB_nonmixed(model, faminfo) | ||
| } | ||
| stats::residuals(model, type = "response") / sig | ||
|
Comment on lines
+52
to
+57
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbogomolovas2 I think this is the same as for performance, which should be fixed. Else, everything looks good to me.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SO, basically, just change it to |
||
| } else { | ||
| .sigma_glmmTMB_nonmixed(model, faminfo) | ||
| r_pearson | ||
| } | ||
| stats::residuals(model) / sig | ||
| } else if (inherits(model, "glm")) { | ||
| stats::rstandard(model, type = "pearson") | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add visual tests later