Skip to content

Commit fb42179

Browse files
committed
docs, add tests
1 parent 7d010cc commit fb42179

File tree

5 files changed

+146
-11
lines changed

5 files changed

+146
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: performance
33
Title: Assessment of Regression Models Performance
4-
Version: 0.12.2.10
4+
Version: 0.12.2.11
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

R/check_dag.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
#' model is correctly adjusted for identifying specific relationships of
77
#' variables, especially directed (maybe also "causal") effects for given
88
#' exposures on an outcome. In case of incorrect adjustments, the function
9-
#' suggest the minimal required variables that should be adjusted for (sometimes
10-
#' also called "controlled for"), i.e. that need to be included in the model.
11-
#' It returns a **dagitty** object that can be visualized with `plot()`.
9+
#' suggests the minimal required variables that should be adjusted for (sometimes
10+
#' also called "controlled for"), i.e. variables that *at least* need to be
11+
#' included in the model. Depending on the goal of the analysis, it is still
12+
#' possible to add more variables to the model than just the minimally required
13+
#' adjustment sets.
1214
#'
1315
#' `check_dag()` is a convenient wrapper around `ggdag::dagify()`,
1416
#' `dagitty::adjustmentSets()` and `dagitty::adjustedNodes()` to check correct
15-
#' adjustment sets. `as.dag()` is a small convenient function to return the
17+
#' adjustment sets. It returns a **dagitty** object that can be visualized with
18+
#' `plot()`. `as.dag()` is a small convenient function to return the
1619
#' dagitty-string, which can be used for the online-tool from the
1720
#' dagitty-website.
1821
#'
@@ -59,7 +62,7 @@
5962
#' The function checks if the model is correctly adjusted for identifying the
6063
#' direct and total effects of the exposure on the outcome. If the model is
6164
#' correctly specified, no adjustment is needed to estimate the direct effect.
62-
#' If the model is not correctly specified, the function suggests the minimal
65+
#' If the model is not correctly specified, the function suggests the minimally
6366
#' required variables that should be adjusted for. The function distinguishes
6467
#' between direct and total effects, and checks if the model is correctly
6568
#' adjusted for both. If the model is cyclic, the function stops and suggests

man/check_dag.Rd

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/check_dag.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,90 @@
131131
All minimal sufficient adjustments to estimate the direct and total effect were done.
132132
133133

134+
# check_dag, different adjustements for total and direct
135+
136+
Code
137+
print(dag)
138+
Output
139+
# Check for correct adjustment sets
140+
- Outcome: outcome
141+
- Exposure: exposure
142+
143+
Identification of direct effects
144+
145+
Incorrectly adjusted!
146+
To estimate the direct effect, at least adjust for `x1` and `x2`.
147+
Currently, the model does not adjust for any variables.
148+
149+
Identification of total effects
150+
151+
Incorrectly adjusted!
152+
To estimate the total effect, at least adjust for `x1`.
153+
Currently, the model does not adjust for any variables.
154+
155+
156+
---
157+
158+
Code
159+
print(dag)
160+
Output
161+
# Check for correct adjustment sets
162+
- Outcome: outcome
163+
- Exposure: exposure
164+
- Adjustment: x1
165+
166+
Identification of direct effects
167+
168+
Incorrectly adjusted!
169+
To estimate the direct effect, at least adjust for `x1` and `x2`.
170+
Currently, the model only adjusts for `x1`.
171+
172+
Identification of total effects
173+
174+
Model is correctly specified.
175+
All minimal sufficient adjustments to estimate the total effect were done.
176+
177+
178+
---
179+
180+
Code
181+
print(dag)
182+
Output
183+
# Check for correct adjustment sets
184+
- Outcome: outcome
185+
- Exposure: exposure
186+
- Adjustment: x2
187+
188+
Identification of direct effects
189+
190+
Incorrectly adjusted!
191+
To estimate the direct effect, at least adjust for `x1` and `x2`.
192+
Currently, the model only adjusts for `x2`.
193+
194+
Identification of total effects
195+
196+
Incorrectly adjusted!
197+
To estimate the total effect, do not adjust for `x2`.
198+
199+
200+
---
201+
202+
Code
203+
print(dag)
204+
Output
205+
# Check for correct adjustment sets
206+
- Outcome: outcome
207+
- Exposure: exposure
208+
- Adjustments: x1 and x2
209+
210+
Identification of direct effects
211+
212+
Model is correctly specified.
213+
All minimal sufficient adjustments to estimate the direct effect were done.
214+
215+
Identification of total effects
216+
217+
Incorrectly adjusted!
218+
To estimate the total effect, do not adjust for `x1` and `x2`.
219+
220+

tests/testthat/test-check_dag.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,45 @@ test_that("check_dag, multiple adjustment sets", {
9191
)
9292
expect_snapshot(print(dag))
9393
})
94+
95+
96+
test_that("check_dag, different adjustements for total and direct", {
97+
dag <- check_dag(
98+
outcome ~ exposure + x1 + x2,
99+
x2 ~ exposure,
100+
exposure ~ x1,
101+
outcome = "outcome",
102+
exposure = "exposure"
103+
)
104+
expect_snapshot(print(dag))
105+
106+
dag <- check_dag(
107+
outcome ~ exposure + x1 + x2,
108+
x2 ~ exposure,
109+
exposure ~ x1,
110+
adjusted = "x1",
111+
outcome = "outcome",
112+
exposure = "exposure"
113+
)
114+
expect_snapshot(print(dag))
115+
116+
dag <- check_dag(
117+
outcome ~ exposure + x1 + x2,
118+
x2 ~ exposure,
119+
exposure ~ x1,
120+
adjusted = "x2",
121+
outcome = "outcome",
122+
exposure = "exposure"
123+
)
124+
expect_snapshot(print(dag))
125+
126+
dag <- check_dag(
127+
outcome ~ exposure + x1 + x2,
128+
x2 ~ exposure,
129+
exposure ~ x1,
130+
adjusted = c("x1", "x2"),
131+
outcome = "outcome",
132+
exposure = "exposure"
133+
)
134+
expect_snapshot(print(dag))
135+
})

0 commit comments

Comments
 (0)