From 7196b1f5390ae8b6e83fbfe72aed1334849176b7 Mon Sep 17 00:00:00 2001 From: jbogomolovas2 Date: Sat, 1 Aug 2026 18:49:16 -0700 Subject: [PATCH 1/5] Use Pearson residuals for glmmTMB/MixMod heteroscedasticity plot --- DESCRIPTION | 6 +++++- NEWS.md | 9 +++++++++ R/plot.check_heteroscedasticity.R | 21 +++++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f01bd7cd4..da7348552 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.14.1.2 +Version: 0.14.1.3 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -43,6 +43,10 @@ Authors@R: role = "ctb", email = "jeffrey.r.stevens@gmail.com", comment = c(ORCID = "0000-0003-2375-1360")), + person(given = "Julius", + family = "Bogomolovas", + role = "ctb", + comment = c(ORCID = "0000-0001-8344-1909")), person(given = "Matthew", family = "Smith", role = "rev", diff --git a/NEWS.md b/NEWS.md index fe0ecf8a3..f7f94273e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,15 @@ * Argument `linewidth` was renamed to `size_line`, to be consistent across the easystats-ecosystem. +## Bug fixes + +* `plot()` for `check_heteroscedasticity()` now uses Pearson residuals for + `glmmTMB` and `MixMod` models. Previously these residuals were divided by a + single scalar, which is only correct when the variance function does not + depend on the mean; for non-mixed binomial and Poisson models that scalar was + 1, so the plot could suggest heteroscedasticity for correctly specified + models. See easystats/performance#926. + # see 0.14.1 ## Changes diff --git a/R/plot.check_heteroscedasticity.R b/R/plot.check_heteroscedasticity.R index f4ca06ab6..07baeb678 100644 --- a/R/plot.check_heteroscedasticity.R +++ b/R/plot.check_heteroscedasticity.R @@ -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 } else { - .sigma_glmmTMB_nonmixed(model, faminfo) + r_pearson } - stats::residuals(model) / sig } else if (inherits(model, "glm")) { stats::rstandard(model, type = "pearson") } else { From 9b481f9e0ed3aa0e9c2916ef7b9fbb26ae1bcd20 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 4 Aug 2026 11:55:46 +0200 Subject: [PATCH 2/5] add reminder, address comments --- R/plot.check_heteroscedasticity.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/R/plot.check_heteroscedasticity.R b/R/plot.check_heteroscedasticity.R index 07baeb678..767acf291 100644 --- a/R/plot.check_heteroscedasticity.R +++ b/R/plot.check_heteroscedasticity.R @@ -34,6 +34,12 @@ plot.see_check_heteroscedasticity <- function( model <- data } + ## TODO: this code, which returns scaled (Pearson) residuals, is + # a duplicate and also present in the performance package. + # we should think about refactoring and move this to + # `insight::get_residuals()`, adding a `standardize` argument. We + # could then. e.g., call `get_residuals(type = "pearson", standardized = TRUE)` + faminfo <- insight::model_info(model) r <- tryCatch( if (inherits(model, "merMod")) { @@ -112,12 +118,12 @@ plot.see_check_heteroscedasticity <- function( ) { return(1) } - betad <- model$fit$par["betad"] + betadisp <- model$fit$par["betadisp"] switch( faminfo$family, - gaussian = exp(0.5 * betad), - Gamma = exp(-0.5 * betad), - exp(betad) + gaussian = exp(0.5 * betadisp), + Gamma = exp(-0.5 * betadisp), + exp(betadisp) ) } From a70bd9624c3308f18df525d581a3b54157d2e723 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 4 Aug 2026 12:38:57 +0200 Subject: [PATCH 3/5] add snaps --- R/plot.check_model.R | 1 - .../plot-check-heteroscedasticity-glm.svg | 681 +++++ .../plot-check-heteroscedasticity-glmmtmb.svg | 681 +++++ .../outliers-plot-low-n.svg | 2688 ++++++++++------- .../test-plot.check_heteroscedasticity.R | 38 + 5 files changed, 2988 insertions(+), 1101 deletions(-) create mode 100644 tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glm.svg create mode 100644 tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glmmtmb.svg diff --git a/R/plot.check_model.R b/R/plot.check_model.R index 04da9c9c9..7f7ce6cd0 100644 --- a/R/plot.check_model.R +++ b/R/plot.check_model.R @@ -147,7 +147,6 @@ plot.see_check_model <- function( # Binned Residuals if (.should_plot(x, check, "BINNED_RESID", "binned_residuals")) { - x$HOMOGENEITY <- NULL # Prevent conflict with standard homogeneity plot fun_args <- c( list(x$BINNED_RESID), common_args, diff --git a/tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glm.svg b/tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glm.svg new file mode 100644 index 000000000..37675d1ec --- /dev/null +++ b/tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glm.svg @@ -0,0 +1,681 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.5 +1.0 +1.5 +2.0 + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 +Fitted values + +|Std. residuals| +Reference line should be flat and horizontal +Homogeneity of Variance + + diff --git a/tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glmmtmb.svg b/tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glmmtmb.svg new file mode 100644 index 000000000..acfb11178 --- /dev/null +++ b/tests/testthat/_snaps/plot.check_heteroscedasticity/plot-check-heteroscedasticity-glmmtmb.svg @@ -0,0 +1,681 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.5 +1.0 +1.5 +2.0 + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 +Fitted values + +|Std. residuals| +Reference line should be flat and horizontal +Homogeneity of Variance + + diff --git a/tests/testthat/_snaps/vdiffr_check_model/outliers-plot-low-n.svg b/tests/testthat/_snaps/vdiffr_check_model/outliers-plot-low-n.svg index 08c2ca5fc..e4cc69dcc 100644 --- a/tests/testthat/_snaps/vdiffr_check_model/outliers-plot-low-n.svg +++ b/tests/testthat/_snaps/vdiffr_check_model/outliers-plot-low-n.svg @@ -18,1162 +18,1650 @@ - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - + + - -200 -220 -240 - -0 -1 -this_male_mated -Counts - - - - -Observed data -Model-predicted data + + + + + + + + + + + + + + + + + + + + + + + + + + +200 +220 +240 + +0 +1 +this_male_mated +Counts + + + + +Observed data +Model-predicted data Model-predicted intervals should include observed data points Posterior Predictive Check - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.4 +-0.2 +0.0 +0.2 +0.4 + +40% +50% +60% +70% +80% +Estimated Probability of this_male_mated +Average residual +Points should be within error bounds +Binned Residuals + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - --0.4 --0.2 -0.0 -0.2 -0.4 - -40% -50% -60% -70% -80% -Estimated Probability of this_male_mated -Average residual -Points should be within error bounds -Binned Residuals + +0.8 +1.0 +1.2 +1.4 + +0.4 +0.5 +0.6 +0.7 +0.8 +Fitted values + +|Std. residuals| +Reference line should be flat and horizontal +Homogeneity of Variance - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -219 -227 -229 -230 -239 - - - - -0.5 -1.0 -0.5 -1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +219 +227 +229 +230 +239 + + + + +0.5 +1.0 +0.5 +1.0 - --20 --10 -0 -10 -20 - -0.00 -0.01 -0.02 -0.03 -Leverage ( -h -i -i -) -Std. Residuals -Points should be inside the contour lines -Influential Observations + +-20 +-10 +0 +10 +20 + +0.00 +0.01 +0.02 +0.03 +Leverage ( +h +i +i +) +Std. Residuals +Points should be inside the contour lines +Influential Observations - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - -0.00 -0.25 -0.50 -0.75 -1.00 - -0.00 -0.25 -0.50 -0.75 -1.00 -Standard Uniform Distribution Quantiles -Sample Quantiles -Dots should fall along the line -Distribution of Quantile Residuals + +0.00 +0.25 +0.50 +0.75 +1.00 + +0.00 +0.25 +0.50 +0.75 +1.00 +Standard Uniform Distribution Quantiles +Sample Quantiles +Dots should fall along the line +Distribution of Quantile Residuals outliers_plot_low_N diff --git a/tests/testthat/test-plot.check_heteroscedasticity.R b/tests/testthat/test-plot.check_heteroscedasticity.R index be8535811..8d8b8cd06 100644 --- a/tests/testthat/test-plot.check_heteroscedasticity.R +++ b/tests/testthat/test-plot.check_heteroscedasticity.R @@ -17,3 +17,41 @@ test_that("`plot.see_check_heteroscedasticity()` snapshot", { fig = plot(result, data = m) ) }) + +test_that("`plot.see_check_heteroscedasticity()`, glmmTMB", { + set.seed(1) + n <- 600 + size <- 20 + x <- runif(n, -3, 3) + d <- data.frame(x = x, y = rbinom(n, size, plogis(-0.5 + 1.2 * x))) + d$f <- size - d$y + + m <- glm(cbind(y, f) ~ x, family = binomial, data = d) + expect_message( + { + out <- performance::check_heteroscedasticity(m) + }, + regex = "There is only a `plot()` method", + fixed = TRUE + ) + set.seed(123) + vdiffr::expect_doppelganger( + title = "plot.check_heteroscedasticity-glm", + fig = plot(out) + ) + + skip_if_not_installed("glmmTMB") + m <- glmmTMB::glmmTMB(cbind(y, f) ~ x, family = binomial, data = d) + expect_message( + { + out <- performance::check_heteroscedasticity(m) + }, + regex = "There is only a `plot()` method", + fixed = TRUE + ) + set.seed(123) + vdiffr::expect_doppelganger( + title = "plot.check_heteroscedasticity-glmmTMB", + fig = plot(out) + ) +}) From c8976244a310ff32dc5bc3b313babe5d3bc258cd Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 4 Aug 2026 13:36:54 +0200 Subject: [PATCH 4/5] update snaps --- .../check-model-heterogeneity-1.svg | 2299 +++++++++++++++++ .../check-model-heterogeneity-2.svg | 1627 ++++++++++++ .../check-normality-default.svg | 133 +- .../check-normality-detrend.svg | 133 +- tests/testthat/test-vdiffr_check_model.R | 22 + 5 files changed, 4078 insertions(+), 136 deletions(-) create mode 100644 tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-1.svg create mode 100644 tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-2.svg diff --git a/tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-1.svg b/tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-1.svg new file mode 100644 index 000000000..cb75ad836 --- /dev/null +++ b/tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-1.svg @@ -0,0 +1,2299 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.6 +0.8 +1.0 +1.2 +1.4 + +0.00 +0.25 +0.50 +0.75 +1.00 +cbind(y, f) +Density + + + +Observed data +Model-predicted data +Model-predicted lines should resemble observed data line +Posterior Predictive Check + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-1.0 +-0.5 +0.0 +0.5 +1.0 + +0% +25% +50% +75% +Estimated Probability of cbind(y, f) +Average residual + +Within error bounds + + + + +no +yes +Points should be within error bounds +Binned Residuals + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.5 +1.0 +1.5 +2.0 + +0.00 +0.25 +0.50 +0.75 +1.00 +Fitted values + +|Std. residuals| +Reference line should be flat and horizontal +Homogeneity of Variance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +180 +389 +414 +174 +369 + + +0.5 +0.5 + + + +-20 +-10 +0 +10 +20 + +0.000 +0.001 +0.002 +0.003 +0.004 +Leverage ( +h +i +i +) +Std. Residuals +Points should be inside the contour lines +Influential Observations + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + +0.00 +0.25 +0.50 +0.75 +1.00 +Standard Uniform Distribution Quantiles +Sample Quantiles +Dots should fall along the line +Distribution of Quantile Residuals +check_model_heterogeneity-1 + + diff --git a/tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-2.svg b/tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-2.svg new file mode 100644 index 000000000..94aef1038 --- /dev/null +++ b/tests/testthat/_snaps/vdiffr_check_model/check-model-heterogeneity-2.svg @@ -0,0 +1,1627 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.6 +0.8 +1.0 +1.2 +1.4 + +0.00 +0.25 +0.50 +0.75 +1.00 +cbind(y, f) +Density + + + +Observed data +Model-predicted data +Model-predicted lines should resemble observed data line +Posterior Predictive Check + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-1.0 +-0.5 +0.0 +0.5 +1.0 + +0% +25% +50% +75% +Estimated Probability of cbind(y, f) +Average residual + +Within error bounds + + + + +no +yes +Points should be within error bounds +Binned Residuals + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.5 +1.0 +1.5 +2.0 + +0.00 +0.25 +0.50 +0.75 +1.00 +Fitted values + +|Std. residuals| +Reference line should be flat and horizontal +Homogeneity of Variance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + +0.00 +0.25 +0.50 +0.75 +1.00 +Standard Uniform Distribution Quantiles +Sample Quantiles +Dots should fall along the line +Distribution of Quantile Residuals +check_model_heterogeneity-2 + + diff --git a/tests/testthat/_snaps/vdiffr_check_model/check-normality-default.svg b/tests/testthat/_snaps/vdiffr_check_model/check-normality-default.svg index 84e2367c5..bcce5c813 100644 --- a/tests/testthat/_snaps/vdiffr_check_model/check-normality-default.svg +++ b/tests/testthat/_snaps/vdiffr_check_model/check-normality-default.svg @@ -27,78 +27,75 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --2 --1 -0 -1 -2 +-2 +-1 +0 +1 +2 --2 --1 -0 -1 -2 +-2 +-1 +0 +1 +2 Standard Normal Distribution Quantiles Sample Quantile Deviations Dots should fall along the line diff --git a/tests/testthat/_snaps/vdiffr_check_model/check-normality-detrend.svg b/tests/testthat/_snaps/vdiffr_check_model/check-normality-detrend.svg index 84e2367c5..bcce5c813 100644 --- a/tests/testthat/_snaps/vdiffr_check_model/check-normality-detrend.svg +++ b/tests/testthat/_snaps/vdiffr_check_model/check-normality-detrend.svg @@ -27,78 +27,75 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --2 --1 -0 -1 -2 +-2 +-1 +0 +1 +2 --2 --1 -0 -1 -2 +-2 +-1 +0 +1 +2 Standard Normal Distribution Quantiles Sample Quantile Deviations Dots should fall along the line diff --git a/tests/testthat/test-vdiffr_check_model.R b/tests/testthat/test-vdiffr_check_model.R index 6612bff91..7ddcc8faf 100644 --- a/tests/testthat/test-vdiffr_check_model.R +++ b/tests/testthat/test-vdiffr_check_model.R @@ -246,3 +246,25 @@ test_that("ppc_range works", { fig = plot(performance::check_model(quine.nb1, x_limits = c(0, 10))) ) }) + +test_that("check_model() with heterogeneity plots works", { + set.seed(1) + n <- 600 + size <- 20 + x <- runif(n, -3, 3) + d <- data.frame(x = x, y = rbinom(n, size, plogis(-0.5 + 1.2 * x))) + d$f <- size - d$y + + m <- glm(cbind(y, f) ~ x, family = binomial, data = d) + expect_doppelganger_with_seed( + title = "check_model_heterogeneity-1", + fig = plot(performance::check_model(m)) + ) + + skip_if_not_installed("glmmTMB") + m <- glmmTMB::glmmTMB(cbind(y, f) ~ x, family = binomial, data = d) + expect_doppelganger_with_seed( + title = "check_model_heterogeneity-2", + fig = plot(performance::check_model(m)) + ) +}) From f0ccb74d86f44b8bcfd220e01d50009aace2abd6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 4 Aug 2026 13:38:53 +0200 Subject: [PATCH 5/5] news --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index f7f94273e..c4fac86b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,10 @@ * Argument `linewidth` was renamed to `size_line`, to be consistent across the easystats-ecosystem. +* `plot()` for `check_heteroscedasticity()` now works for GLM's and models from + package *glmmTMB*. Previously, `check_heteroscedasticity()` worked for linear + models only. + ## Bug fixes * `plot()` for `check_heteroscedasticity()` now uses Pearson residuals for