From cb26681f623d7b71f5158468b619c0f2a31b168b Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 18 Mar 2024 11:54:18 +0100 Subject: [PATCH 1/5] Revising `check_model()` Fixes #697 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2dcc2ae85..0f23a585c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.10.9.9 +Version: 0.10.9.10 Authors@R: c(person(given = "Daniel", family = "Lüdecke", From 8137ac339838149a1246ea4cc40f3356fb486433 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 18 Mar 2024 12:07:06 +0100 Subject: [PATCH 2/5] docs --- R/check_model.R | 13 +++++++------ man/check_model.Rd | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/R/check_model.R b/R/check_model.R index 6be17be22..21ca380d5 100644 --- a/R/check_model.R +++ b/R/check_model.R @@ -144,12 +144,13 @@ #' inside the error bounds. See [`binned_residuals()`] for further details. #' #' @section Residuals for (Generalized) Linear Models: -#' Plots that check the normality of residuals (Q-Q plot) or the homogeneity of -#' variance use standardized Pearson's residuals for generalized linear models, -#' and standardized residuals for linear models. The plots for the normality of -#' residuals (with overlayed normal curve) and for the linearity assumption use -#' the default residuals for `lm` and `glm` (which are deviance residuals for -#' `glm`). +#' Plots that check the homogeneity of variance use standardized Pearson's +#' residuals for generalized linear models, and standardized residuals for +#' linear models. The plots for the normality of residuals (with overlayed +#' normal curve) and for the linearity assumption use the default residuals +#' for `lm` and `glm` (which are deviance residuals for `glm`). The Q-Q plots +#' use simulated residuals (see [`simulate_residuals()`]) for non-Gaussian +#' models and standardized residuals for linear models. #' #' @section Troubleshooting: #' For models with many observations, or for more complex models in general, diff --git a/man/check_model.Rd b/man/check_model.Rd index 4bdea6ebe..d0d7e765b 100644 --- a/man/check_model.Rd +++ b/man/check_model.Rd @@ -212,12 +212,13 @@ inside the error bounds. See \code{\link[=binned_residuals]{binned_residuals()}} \section{Residuals for (Generalized) Linear Models}{ -Plots that check the normality of residuals (Q-Q plot) or the homogeneity of -variance use standardized Pearson's residuals for generalized linear models, -and standardized residuals for linear models. The plots for the normality of -residuals (with overlayed normal curve) and for the linearity assumption use -the default residuals for \code{lm} and \code{glm} (which are deviance residuals for -\code{glm}). +Plots that check the homogeneity of variance use standardized Pearson's +residuals for generalized linear models, and standardized residuals for +linear models. The plots for the normality of residuals (with overlayed +normal curve) and for the linearity assumption use the default residuals +for \code{lm} and \code{glm} (which are deviance residuals for \code{glm}). The Q-Q plots +use simulated residuals (see \code{\link[=simulate_residuals]{simulate_residuals()}}) for non-Gaussian +models and standardized residuals for linear models. } \section{Troubleshooting}{ From 0936c5e3952b4141681c0d9b4222983484de2a8c Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 25 Mar 2024 09:21:08 +0100 Subject: [PATCH 3/5] version bump --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 68ce7de42..8a6cafbc4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.11.0 +Version: 0.11.0.1 Authors@R: c(person(given = "Daniel", family = "Lüdecke", From d10c7c664d975fb3cef49a87294ded1d15ca40c3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 26 Mar 2024 11:56:23 +0100 Subject: [PATCH 4/5] version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7ff8da559..5998603cd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.11.0.1 +Version: 0.11.0.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", From 6518a4d8003b37f113ef296ec0ec2018a18455fc Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 26 Mar 2024 12:06:41 +0100 Subject: [PATCH 5/5] debug mode --- R/check_model_diagnostics.R | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/R/check_model_diagnostics.R b/R/check_model_diagnostics.R index 431a2bc0f..a955abf20 100644 --- a/R/check_model_diagnostics.R +++ b/R/check_model_diagnostics.R @@ -300,10 +300,20 @@ predicted <- simres$fittedPredictedResponse d <- data.frame(Predicted = predicted) + # extract sigma, we scale the residuals by dividing by sigma + sig <- if (faminfo$is_mixed) { + sqrt(insight::get_variance_residual(model)) + } else if (inherits(model, "glmmTMB")) { + .sigma_glmmTMB_nonmixed(model, faminfo) + } else { + insight::get_sigma(model) + } + # residuals based on simulated residuals - but we want normally distributed residuals d$Residuals <- stats::residuals(simres, quantile_function = stats::qnorm, ...) d$Res2 <- d$Residuals^2 - d$StdRes <- insight::get_residuals(model, type = "pearson") + # d$StdRes <- insight::get_residuals(model, type = "pearson") + d$StdRes <- d$Residuals / sig # data for poisson models if (faminfo$is_poisson && !faminfo$is_zero_inflated) { @@ -368,6 +378,14 @@ .diag_overdispersion <- function(model, ...) { + + ## TODO: remove this code later -it's just to test the ".new_diag_overdispersion" + ## function. Set options(performance_new_overdispersion = TRUE) to use the new + ## function. + if (isTRUE(getOption("performance_new_overdispersion"))) { + return(.new_diag_overdispersion(model, ...)) + } + faminfo <- insight::model_info(model) # data for poisson models