diff --git a/R/check_heterogeneity_bias.R b/R/check_heterogeneity_bias.R index b87aa9962..d9bb337f9 100644 --- a/R/check_heterogeneity_bias.R +++ b/R/check_heterogeneity_bias.R @@ -31,9 +31,9 @@ check_heterogeneity_bias <- function(x, select = NULL, group = NULL) { if (insight::is_model(x)) { group <- insight::find_random(x, split_nested = TRUE, flatten = TRUE) if (is.null(group)) { - insight::format_error("Model is no mixed model. Please provide a mixed model, or a data frame and arguments `select` and `group`.") + insight::format_error("Model is no mixed model. Please provide a mixed model, or a data frame and arguments `select` and `group`.") # nolint } - data <- insight::get_data(x, source = "mf", verbose = FALSE) + my_data <- insight::get_data(x, source = "mf", verbose = FALSE) select <- insight::find_predictors(x, effects = "fixed", component = "conditional", flatten = TRUE) } else { if (inherits(select, "formula")) { @@ -42,15 +42,15 @@ check_heterogeneity_bias <- function(x, select = NULL, group = NULL) { if (inherits(group, "formula")) { group <- all.vars(group) } - data <- x + my_data <- x } - unique_groups <- .n_unique(data[[group]]) + unique_groups <- .n_unique(my_data[[group]]) combinations <- expand.grid(select, group) result <- Map(function(predictor, id) { # demean predictor - d <- datawizard::demean(data, select = predictor, group = id, verbose = FALSE) + d <- datawizard::demean(my_data, select = predictor, group = id, verbose = FALSE) # get new names within_name <- paste0(predictor, "_within") diff --git a/tests/testthat/test-check_outliers.R b/tests/testthat/test-check_outliers.R index ec9bb7ffc..02c6804a5 100644 --- a/tests/testthat/test-check_outliers.R +++ b/tests/testthat/test-check_outliers.R @@ -87,12 +87,17 @@ test_that("mcd which", { # (not clear why method mcd needs a seed) set.seed(42) expect_identical( - tail(which(check_outliers(mtcars[1:4], method = "mcd", threshold = 45))), + tail(which(check_outliers(mtcars[1:4], method = "mcd", threshold = 45, verbose = FALSE))), 31L ) - out <- check_outliers(mtcars, method = "mcd") + expect_warning( + { + out <- check_outliers(mtcars, method = "mcd") + }, + regex = "The sample size is too small" + ) expect_identical(sum(out), 8L) - out <- check_outliers(mtcars, method = "mcd", percentage_central = 0.5) + out <- check_outliers(mtcars, method = "mcd", percentage_central = 0.5, verbose = FALSE) expect_identical(sum(out), 15L) }) @@ -228,7 +233,8 @@ test_that("multiple methods with ID", { mahalanobis = 20, mahalanobis_robust = 25, mcd = 25, optics = 14, lof = 0.005 ), - ID = "car" + ID = "car", + verbose = FALSE )) expect_identical( x$outlier_var$zscore$mpg$car,