Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Aug 9, 2024
1 parent 0f7dbf7 commit 0296047
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
51 changes: 51 additions & 0 deletions tests/testthat/_snaps/check_dag.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,54 @@
All minimal sufficient adjustments to estimate the total effect were done.

# check_dag, multiple adjustment sets

Code
print(dag)
Output
# Check for correct adjustment sets
- Outcome: exam
- Exposure: podcast
Identification of direct effects
Incorrectly adjusted!
To estimate the direct effect, also adjust for one of the following sets:
- alertness, prepared
- alertness, skills_course
- mood, prepared
- mood, skills_course.
Currently, the model does not adjust for any variables.
Identification of total effects
Incorrectly adjusted!
To estimate the total effect, also adjust for one of the following sets:
- alertness, prepared
- alertness, skills_course
- mood, prepared
- mood, skills_course.
Currently, the model does not adjust for any variables.

---

Code
print(dag)
Output
# Check for correct adjustment sets
- Outcome: exam
- Exposure: podcast
- Adjustments: alertness and prepared
Identification of direct effects
Model is correctly specified.
All minimal sufficient adjustments to estimate the direct effect were done.
Identification of total effects
Model is correctly specified.
All minimal sufficient adjustments to estimate the total effect were done.

28 changes: 27 additions & 1 deletion tests/testthat/test-check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ test_that("check_dag", {
wt ~ disp + cyl,
wt ~ am
)
dag
expect_snapshot(print(dag))
})

Expand All @@ -65,3 +64,30 @@ test_that("check_dag, cylic error", {
regex = "Model is cyclic"
)
})


test_that("check_dag, multiple adjustment sets", {
dag <- check_dag(
podcast ~ mood + humor + skills_course,
alertness ~ mood,
mood ~ humor,
prepared ~ skills_course,
exam ~ alertness + prepared,
coords = ggdag::time_ordered_coords(),
exposure = "podcast",
outcome = "exam"
)
expect_snapshot(print(dag))
dag <- check_dag(
podcast ~ mood + humor + skills_course,
alertness ~ mood,
mood ~ humor,
prepared ~ skills_course,
exam ~ alertness + prepared,
adjusted = c("alertness", "prepared"),
exposure = "podcast",
outcome = "exam",
coords = ggdag::time_ordered_coords()
)
expect_snapshot(print(dag))
})

0 comments on commit 0296047

Please sign in to comment.