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 …