3.2 — Causal Inference II: DAGs — R Practice
Set Up
To minimize confusion, I suggest creating a new R Project
(e.g. regression_practice
) and storing any data in that folder on your computer.
Alternatively, I have made a project in R Studio Cloud that you can use (and not worry about trading room computer limitations), with the data already inside (you will still need to assign it to an object).
DAG Practice
For each of the following examples:
- Write out all of the causal pathways from
X
(treatment of interest) toY
(outcome of interest).
- Write out all of the causal pathways from
- Identify which variable(s) need to be controlled for to estimate the causal effect of
X
onY
. You can usedagitty.net
to help you, but you should start trying to recognize these on your own!
- Identify which variable(s) need to be controlled for to estimate the causal effect of
- Draw the DAGs in
r
usingggdag
. After setting up the dag withdagify()
(and specifyingexposure
andoutcome
insidedagify
), pipe that intoggdag()
. Try again piping it instead intoggdag_status()
(to highlight what is X and what is Y). Try again piping it instead intoggdag_adjustment_set()
to show what needs to be controlled.
- Draw the DAGs in
Don’t forget to install ggdag
!