Debian Codegraph @

tests/testthat/test-mediation.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("modeltests")
4 library(modeltests)
5
6 skip_if_not_installed("mediation")
7 suppressPackageStartupMessages(library(mediation))
8
9 data(jobs)
10 b <- lm(job_seek ~ treat + econ_hard + sex + age, data = jobs)
11 c <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data = jobs)
12 mod <- mediate(b, c, sims = 50, treat = "treat", mediator = "job_seek")
13
14 test_that("mediation tidier arguments", {
15 check_arguments(tidy.mediate)
16 })
17
18 test_that("tidy.mediation", {
19 td1 <- tidy(mod, conf.int = TRUE, conf.level = 0.99)
20 td2 <- tidy(mod, conf.int = TRUE)
21
22 check_tidy_output(td1)
23 check_tidy_output(td2)
24
25 check_dims(td1, 4, 6)
26 })
27
28 test_that("tidy.mediate errors informatively", {
29 # Test error for psych package mediate object
30 psych_mediate <- structure(list(), class = c("mediate", "psych"))
31 expect_snapshot(error = TRUE, tidy(psych_mediate))
32 })