Skip to content

Commit

Permalink
check_predictions() fails when outcome is log-transformed and named l…
Browse files Browse the repository at this point in the history
…ike a valid function

Fixes #722
  • Loading branch information
strengejacke committed Jul 13, 2024
1 parent 2c0953f commit ca990bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion R/check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit ca990bd

Please sign in to comment.