library(ggdag)
library(tidyverse)
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:
Follows the same syntax as lm()
, but using dagify()
:
= dagify(Y ~ X + A + B,
dag ~ B + C,
A ~ B + C + D,
X ~ D,
C exposure = "X",
outcome = "Y")
Plot:
ggdag(dag)
Look at all the paths:
ggdag_paths(dag)
Identify controls:
ggdag_adjustment_set(dag)