```
library(tidyverse) # your friend and mine
library(dagitty) # for working with DAGs
library(ggdag) # for drawing DAGs in R
```

# 3.2 — DAGs — R Practice

# Required Packages

Load all the required packages we will use by running (clicking the green play button) the chunk below:

`set.seed(20) # using this number means all "random" generated objects will be identical for all of us!`

For each of the following examples:

- Write out
*all*of the causal pathways from`X`

(treatment of interest) to`Y`

(outcome of interest). - Identify which variable(s) need to be controlled to estimate the causal effect of
`X`

on`Y`

. You can use`dagitty.net`

to help you, but you should start trying to recognize these on your own! - Draw the DAGs in
`r`

using`ggdag`

. After setting up the dag with`dagify()`

(and specifying`exposure`

and`outcome`

inside`dagify`

), pipe that into`ggdag()`

. Try again piping it instead into`ggdag_status()`

(to highlight what is X and what is Y). Try again piping it instead into`ggdag_adjustment_set()`

to show what needs to be controlled.

Don’t forget to install `ggdag`

and `dagitty`

!

## Question 1

### Part I

Pathways:

- \(X \rightarrow Y\) (causal, front door)
- \(X \leftarrow Z \rightarrow Y\) (not causal, back door)