From 5396e4f1773e026c84240254e4996d2a18d878f2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Aug 2024 19:08:46 +0200 Subject: [PATCH] wordlist, tests --- inst/WORDLIST | 4 ++ tests/testthat/_snaps/check_dag.md | 92 ++++++++++++++++++++++++++++++ tests/testthat/test-check_dag.R | 34 +++++++++++ 3 files changed, 130 insertions(+) create mode 100644 tests/testthat/_snaps/check_dag.md create mode 100644 tests/testthat/test-check_dag.R diff --git a/inst/WORDLIST b/inst/WORDLIST index e5e90d844..9817a3a47 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -43,6 +43,7 @@ Cribari Cronbach's Crujeiras Csaki +DAGs DBSCAN DOI Datenerhebung @@ -162,6 +163,7 @@ Nordhausen Normed ORCID OSF +OSX Olkin PNFI Pek @@ -251,6 +253,7 @@ brmsfit cauchy clusterable concurvity +dagitty datawizard dbscan der @@ -267,6 +270,7 @@ fixest fpsyg gam geoms +ggdag ggplot gjo glm diff --git a/tests/testthat/_snaps/check_dag.md b/tests/testthat/_snaps/check_dag.md new file mode 100644 index 000000000..a3c38cb1a --- /dev/null +++ b/tests/testthat/_snaps/check_dag.md @@ -0,0 +1,92 @@ +# check_dag + + Code + print(dag) + Output + # Correct adjustments for identifying direct effects + + Model is correctly specified. + - Outcome: y + - Exposure: x + + No adjustment needed to estimate the direct effect of x on y. + + # Correct adjustments for identifying total effects + + Model is correctly specified. + - Outcome: y + - Exposure: x + + No adjustment needed to estimate the total effect of x on y. + + +--- + + Code + print(dag) + Output + # Correct adjustments for identifying direct effects + + Model is correctly specified. + - Outcome: y + - Exposure: x + + All minimal sufficient adjustments to estimate the direct effect were done. + + # Correct adjustments for identifying total effects + + Model is correctly specified. + - Outcome: y + - Exposure: x + + All minimal sufficient adjustments to estimate the total effect were done. + + +--- + + Code + print(dag) + Output + # Correct adjustments for identifying direct effects + + Incorrectly adjusted! + - Outcome: y + - Exposure: x + + To estimate the direct effect, also adjust for: b. + Currently, the model does not adjust for any variables. + + # Correct adjustments for identifying total effects + + Incorrectly adjusted! + - Outcome: y + - Exposure: x + + To estimate the total effect, also adjust for: b. + Currently, the model does not adjust for any variables. + + +--- + + Code + print(dag) + Output + # Correct adjustments for identifying direct effects + + Incorrectly adjusted! + - Outcome: y + - Exposure: x + + To estimate the direct effect, also adjust for: b and c. + Currently, the model currently only adjusts for c. + + # Correct adjustments for identifying total effects + + Incorrectly adjusted! + - Outcome: y + - Exposure: x + + To estimate the total effect, also adjust for: b and c. + Currently, the model currently only adjusts for c. + + diff --git a/tests/testthat/test-check_dag.R b/tests/testthat/test-check_dag.R new file mode 100644 index 000000000..7dbcf065d --- /dev/null +++ b/tests/testthat/test-check_dag.R @@ -0,0 +1,34 @@ +skip_on_cran() +skip_if_not_installed("ggdag") +skip_if_not_installed("dagitty") + +test_that("check_dag", { + dag <- check_dag( + y ~ x + b, + outcome = "y", + exposure = "x" + ) + expect_snapshot(print(dag)) + dag <- check_dag( + y ~ x + b, + outcome = "y", + exposure = "x", + adjusted = "b" + ) + expect_snapshot(print(dag)) + dag <- check_dag( + y ~ x + b + c, + x ~ b, + outcome = "y", + exposure = "x" + ) + expect_snapshot(print(dag)) + dag <- check_dag( + y ~ x + b + c, + x ~ b, + outcome = "y", + exposure = "x", + adjusted = "c" + ) + expect_snapshot(print(dag)) +})