Skip to content

Commit

Permalink
test, lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 4, 2024
1 parent bb17417 commit 49b885f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 5 additions & 5 deletions R/check_heterogeneity_bias.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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")
Expand Down
14 changes: 10 additions & 4 deletions tests/testthat/test-check_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 49b885f

Please sign in to comment.