Skip to content

Commit

Permalink
add snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 13, 2024
1 parent 1d73022 commit 38d5a03
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ print.check_dag <- function(x, ...) {
"\nTo estimate the ", i, " effect, do ",
insight::color_text("not", "italic"),
" adjust for ",
datawizard::text_concatenate(out$current_adjustments, enclose = "`"),
insight::color_text(datawizard::text_concatenate(out$current_adjustments, enclose = "`"), "red"),
"."
)
} else if (any(sufficient_adjustments)) {
Expand Down Expand Up @@ -463,7 +463,7 @@ print.check_dag <- function(x, ...) {
if (length(missing_vars) > 0) {
msg <- paste0(
msg, " You possibly also need to adjust for ",
insight::color_text(datawizard::text_concatenate(missing_vars, enclose = "`"), "yellow"),
insight::color_text(datawizard::text_concatenate(missing_vars, enclose = "`"), "green"),
" to block biasing paths."
)
}
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/_snaps/check_dag.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@
All minimal sufficient adjustments to estimate the direct and total effect were done.

---

Code
print(dag)
Output
# Check for correct adjustment sets
- Outcome: exam
- Exposure: podcast
- Adjustment: alertness
Identification of direct and total effects
Incorrectly adjusted!
To estimate the direct and total effect, at least adjust for one of the following sets:
- alertness, prepared
- alertness, skills_course.
Currently, the model only adjusts for `alertness`. You possibly also need to adjust for `prepared` and `skills_course` to block biasing paths.

# check_dag, different adjustements for total and direct

Code
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ test_that("check_dag, multiple adjustment sets", {
coords = ggdag::time_ordered_coords()
)
expect_snapshot(print(dag))
dag <- check_dag(
podcast ~ mood + humor + skills_course,
alertness ~ mood,
mood ~ humor,
prepared ~ skills_course,
exam ~ alertness + prepared,
coords = ggdag::time_ordered_coords(),
adjusted = "alertness",
exposure = "podcast",
outcome = "exam"
)
expect_snapshot(print(dag))
})


Expand Down

0 comments on commit 38d5a03

Please sign in to comment.