From 7e273b425a510078371ea2f189c66e8914773836 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 13 Jul 2024 23:42:13 +0200 Subject: [PATCH 1/2] check_predictions() fails when outcome is log-transformed and named like a valid function (#750) --- DESCRIPTION | 2 +- R/check_predictions.R | 2 +- tests/testthat/test-check_model.R | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8ea3d81df..e8b5bc7d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.0.9 +Version: 0.12.0.10 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/R/check_predictions.R b/R/check_predictions.R index e9d05fdfd..e9ee08c78 100644 --- a/R/check_predictions.R +++ b/R/check_predictions.R @@ -510,7 +510,7 @@ plot.performance_pp_check <- function(x, ...) { if (is.null(plus_minus)) { plus_minus <- .safe(eval(parse(text = gsub("log\\(([^,\\+)]*)(.*)\\)", "\\1", resp_string)))) } - if (is.null(plus_minus)) { + if (is.null(plus_minus) || !is.numeric(plus_minus)) { sims[] <- lapply(sims, exp) } else { sims[] <- lapply(sims, function(i) exp(i) - plus_minus) diff --git a/tests/testthat/test-check_model.R b/tests/testthat/test-check_model.R index 4e23653b3..097f089a5 100644 --- a/tests/testthat/test-check_model.R +++ b/tests/testthat/test-check_model.R @@ -108,3 +108,13 @@ test_that("`check_model()` no warnings for quasipoisson", { expect_message(check_model(model1, verbose = TRUE), regex = "Not enough") expect_silent(check_model(model1)) }) + + +test_that("`check_model()` with transformed response when named as function", { + data(mtcars) + # rename variable, so it equals to a valid R function + mtcars$rt <- mtcars$mpg + model <- lm(log(rt) ~ disp, data = mtcars) + out <- check_predictions(model) + expect_s3_class(out, "performance_pp_check") +}) From 49ddd909a4e4b17509994b83e7b3a0f6e3e57253 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 13 Jul 2024 23:43:24 +0200 Subject: [PATCH 2/2] news --- NEWS.md | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index 14f4c4e3c..bf8f36f70 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,20 +7,26 @@ the null model fails, or when you already have fit the null model and want to save time. -* `icc()` and `r2_nakagawa()` get a `approximation` argument indicating the +* `icc()` and `r2_nakagawa()` get a `approximation` argument indicating the approximation method for the distribution-specific (residual) variance. See Nakagawa et al. 2017 for details. -* `icc()` and `r2_nakagawa()` get a `model_component` argument indicating the +* `icc()` and `r2_nakagawa()` get a `model_component` argument indicating the component for zero-inflation or hurdle models. -* `performance_rmse()` (resp. `rmse()`) can now compute analytical and +* `performance_rmse()` (resp. `rmse()`) can now compute analytical and bootstrapped confidence intervals. The function gains following new arguments: `ci`, `ci_method` and `iterations`. -* New function `r2_ferrari()` to compute Ferrari & Cribari-Neto's R2 for +* New function `r2_ferrari()` to compute Ferrari & Cribari-Neto's R2 for generalized linear models, in particular beta-regression. +## Bug fixes + +* Fixed issue in `check_model()` when model contained a transformed response + variable that was named like a valid R function name (e.g., `lm(log(lapply) ~ x)`, + when data contained a variable named `lapply`). + # performance 0.12.0 ## Breaking @@ -36,7 +42,7 @@ * Improved documentation and new vignettes added. -* `check_model()` gets a `base_size` argument, to set the base font size for plots. +* `check_model()` gets a `base_size` argument, to set the base font size for plots. * `check_predictions()` for `stanreg` and `brmsfit` models now returns plots in the usual style as for other models and no longer returns plots from @@ -177,7 +183,7 @@ # performance 0.10.6 -## General +## General * Support for `nestedLogit` models. @@ -250,7 +256,7 @@ * `model_performance()`, `check_overdispersion()`, `check_outliers()` and `r2()` now work with objects of class `fixest_multi` (@etiennebacher, #554). - + * `model_performance()` can now return the "Weak instruments" statistic and p-value for models of class `ivreg` with `metrics = "weak_instruments"` (@etiennebacher, #560). @@ -322,8 +328,8 @@ * Fixed issues in `check_model()` for models with convergence issues that lead to `NA` values in residuals. - -* Fixed bug in `check_outliers` whereby passing multiple elements to the + +* Fixed bug in `check_outliers` whereby passing multiple elements to the threshold list generated an error (#496). * `test_wald()` now warns the user about inappropriate F test and calls @@ -351,16 +357,16 @@ * `check_normality()`, `check_homogeneity()` and `check_symmetry()` now works for `htest` objects. -* Print method for `check_outliers()` changed significantly: now states the - methods, thresholds, and variables used, reports outliers per variable (for - univariate methods) as well as any observation flagged for several - variables/methods. Includes a new optional ID argument to add along the +* Print method for `check_outliers()` changed significantly: now states the + methods, thresholds, and variables used, reports outliers per variable (for + univariate methods) as well as any observation flagged for several + variables/methods. Includes a new optional ID argument to add along the row number in the output (@rempsyc #443). -* `check_outliers()` now uses more conventional outlier thresholds. The `IQR` +* `check_outliers()` now uses more conventional outlier thresholds. The `IQR` and confidence interval methods now gain improved distance scores that are continuous instead of discrete. - + ## Bug Fixes * Fixed wrong *z*-score values when using a vector instead of a data frame in @@ -383,7 +389,7 @@ ## Changes to functions -* `check_model()` gains a `show_dots` argument, to show or hide data points. +* `check_model()` gains a `show_dots` argument, to show or hide data points. This is particular useful for models with many observations, where generating the plot would be very slow. @@ -923,4 +929,3 @@ * Fixed issue in `check_heteroscedasticity()` for *aov* objects. * Fixed issues for *lmrob* and *glmrob* objects. -