Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 18, 2024
1 parent a6fd86d commit 54327de
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/testthat/test-check_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,40 @@ test_that("check_outliers with invald data", {
regex = "No numeric variables found"
)
})


test_that("check_outliers with DHARMa", {
skip_if_not_installed("DHARMa")
mt1 <- mtcars[, c(1, 3, 4)]
# create some fake outliers and attach outliers to main df
mt2 <- rbind(mt1, data.frame(
mpg = c(37, 40), disp = c(300, 400),
hp = c(110, 120)
))
# fit model with outliers
model <- lm(disp ~ mpg + hp, data = mt2)
set.seed(123)
res <- simulate_residuals(model)
out <- check_outliers(res)
expect_equal(
out,
structure(
list(
Coefficient = 0.0294117647058824, Expected = 0.00796812749003984,
CI_low = 0.000744364234690261, CI_high = 0.153267669560318,
p_value = 0.238146844116552
),
class = c("check_outliers_simres", "list")
),
ignore_attr = TRUE,
tolerance = 1e-4
)
expect_identical(
capture.output(print(out)),
c(
"# Outliers detection", "", " Proportion of observed outliers: 2.94%",
" Proportion of expected outliers: 0.80%, 95% CI [0.07, 15.33]",
""
)
)
})

0 comments on commit 54327de

Please sign in to comment.