DAGs

In-class example

Here’s the code we’ll be using in class. Download it and store it with the rest of your materials for this course. If simply clicking doesn’t trigger download, you should right-click and select “save link as…”

Example

We write dags using ggdag package:

library(ggdag)
library(tidyverse)

Follows the same syntax as lm(), but using dagify():

dag = dagify(Y ~ X + A + B,
       A ~ B + C,
       X ~ B + C + D,
       C ~ D,
       exposure = "X", 
       outcome = "Y")

Plot:

ggdag(dag)

Look at all the paths:

ggdag_paths(dag)

Identify controls:

ggdag_adjustment_set(dag)