diff --git a/R/check_dag.R b/R/check_dag.R index 5c6ba3462..e0535a0dd 100644 --- a/R/check_dag.R +++ b/R/check_dag.R @@ -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)) { @@ -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." ) } diff --git a/tests/testthat/_snaps/check_dag.md b/tests/testthat/_snaps/check_dag.md index 146986c7d..0c3b3233d 100644 --- a/tests/testthat/_snaps/check_dag.md +++ b/tests/testthat/_snaps/check_dag.md @@ -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 diff --git a/tests/testthat/test-check_dag.R b/tests/testthat/test-check_dag.R index 7bde379f1..c3d22b32a 100644 --- a/tests/testthat/test-check_dag.R +++ b/tests/testthat/test-check_dag.R @@ -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)) })