Load packages
library(tidyverse)
library(ggdag)
library(dagitty)
Define DAG
dag1_str <- 'dag {
C [pos = "2,2"]
X [exposure, pos = "1,1"]
Y [outcome, pos = "3,1"]
C -> X
C -> Y
}'
Plot DAGs
First tidify:
dag1 <- dagitty(dag1_str)
dag1_tidy <- tidy_dagitty(dag1)
dag1_tidy
#> # A DAG with 3 nodes and 2 edges
#> #
#> # Exposure: X
#> # Outcome: Y
#> #
#> # A tibble: 4 x 8
#> name x y direction to xend yend circular
#> <chr> <int> <int> <fct> <chr> <int> <int> <lgl>
#> 1 C 2 2 -> X 1 1 FALSE
#> 2 C 2 2 -> Y 3 1 FALSE
#> 3 X 1 1 <NA> <NA> NA NA FALSE
#> 4 Y 3 1 <NA> <NA> NA NA FALSE
Then plot:
ggdag(dag1_tidy) + theme_dag()
Equivalence class
ggdag_equivalent_dags(confounder_triangle()) + theme_dag()
ggdag_equivalent_dags(dag1_tidy) + theme_dag()