38.3 Example DAG
library(dagitty)
library(ggdag)
dag <- dagitty("dag {
X -> Z -> Y
Z <- U -> Y
}")
coordinates(dag) <- list(
x = c(X = 1, Z = 2, Y = 3, U = 1.5),
y = c(X = 1, Z = 1, Y = 1, U = 2)
)
ggdag(dag) +
theme_dag()
This DAG has:
- A mediator path: X→Z→Y
- A backdoor path through an unobserved confounder: X←U→Y
Use adjustmentSets(dag, exposure = "X", outcome = "Y")
to identify a valid adjustment set.