From 5660f85502ee5912fcd380d97c44297f51dba247 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Sep 2023 11:18:30 +0200 Subject: [PATCH 1/2] Error: `check_model()` not implemented for models of class `lm` yet Fixes #629 --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ R/check_model_diagnostics.R | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3b95351d9..19bada6a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.10.5.4 +Version: 0.10.5.5 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index 40e57d346..47fad4e59 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,11 @@ the previous method, which used `parallel::detectCores()`. Now you should set the number of cores via `options(mc.cores = 4)`. +## Bug fixes + +* Fixed issues is `check_model()` for models that used data sets with + variables of class `"haven_labelled"`. + # performance 0.10.5 ## Changes to functions diff --git a/R/check_model_diagnostics.R b/R/check_model_diagnostics.R index 3b86799cc..34556d578 100644 --- a/R/check_model_diagnostics.R +++ b/R/check_model_diagnostics.R @@ -153,7 +153,7 @@ # prepare data for normality of residuals plot ---------------------------------- .diag_norm <- function(model, verbose = TRUE) { - r <- try(stats::residuals(model), silent = TRUE) + r <- try(as.numeric(stats::residuals(model)), silent = TRUE) if (inherits(r, "try-error")) { insight::format_alert(sprintf("Non-normality of residuals could not be computed. Cannot extract residuals from objects of class '%s'.", class(model)[1])) @@ -212,8 +212,8 @@ ncv <- tryCatch( { data.frame( - x = stats::fitted(model), - y = stats::residuals(model) + x = as.numeric(stats::fitted(model)), + y = as.numeric(stats::residuals(model)) ) }, error = function(e) { From 65ffded0fd28f5fe42ed393d2c5f5ab64fc1fb41 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Sep 2023 11:20:21 +0200 Subject: [PATCH 2/2] fix --- R/check_model_diagnostics.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check_model_diagnostics.R b/R/check_model_diagnostics.R index 34556d578..371e32609 100644 --- a/R/check_model_diagnostics.R +++ b/R/check_model_diagnostics.R @@ -183,7 +183,7 @@ n_params <- tryCatch(model$rank, error = function(e) insight::n_parameters(model)) infl <- stats::influence(model, do.coef = FALSE) - resid <- insight::get_residuals(model) + resid <- as.numeric(insight::get_residuals(model)) std_resid <- tryCatch(stats::rstandard(model, infl), error = function(e) resid)