```
# Removing previous files and setting the directory
rm(list = ls())
setwd("/Users/bgpopescu/Dropbox/john_cabot/teaching/stats/week11/")
library("tidyverse") # For dplyr, ggplot, and friends
library("ggdag") # For plotting DAGs
library("dagitty") # For working with DAG logic
library("ggrepel")
library("modelsummary")
library("lemon")
library("MatchIt")
library("broom")
```

# Lab 11: Statistics

DAGs and Matching

# 1 Intro

In this lab, we learn about DAGs and Matching.

# 2 DAGs

DAGs stand for directed acyclic graphs. These are theoretical models that generated the data. This type of graph tells you what you should control for to isolate and identify a causal effect. The easiest way to quickly build DAGs and find adjustment sets and testable implications is to use dagitty.net. It is easiest if you draw your diagrams on dagitty.net and then in R using the `ggdag`

and `dagitty`

packages. You can go to the Launch DAGitty online in your browser section.

## 2.1 Loading relevant packages

The general process for making and working with DAGs in R is to create a DAG object with `dagify()`

and then plot it with `ggdag()`

. The syntax for `dagify()`

is similar to `lm()`

. For example, if we think that y is caused by a, b, and c, we would write `y ~ a + b + c`

. Similarly, if we think that a is caused by b and c, we would write `a ~ b + c`

. If `y ~ a + b + c`

and `a ~ b + c`

are true at the same time, then b and c are called confounders.

## 2.2 Creating a simple DAG

```
# Creating a basic DAG
<- dagify(
simple_dag ~ a + b + c,
y ~ b + c)
a
ggdag(simple_dag)
```