Skip to content

Commit

Permalink
simple_two_arm_design no longer gitignored
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspercooper committed Aug 25, 2018
1 parent ccd0405 commit a61bb8f
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -4,5 +4,4 @@
.Ruserdata
vignettes/*.html
vignettes/*.R
vignettes/simple_two_arm.Rmd
.DS_Store
97 changes: 97 additions & 0 deletions vignettes/simple_two_arm.Rmd
@@ -0,0 +1,97 @@
---
title: "Two-Arm Experiment"
output: rmarkdown::html_vignette
bibliography: bib.bib
vignette: >
%\VignetteIndexEntry{Two-Arm Experiment}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---


```{r MIDA, echo = FALSE,include = FALSE}
library(DesignLibrary)
library(knitr)
```


Often we want to learn about the causal effect of one thing on something else -- say, the effect of taking a pill on a person becoming healthy. We can define the effect of a cause on an outcome as the difference of how the outcomes potentially would have looked under two states of the world: the potential outcome in a world where the cause is present and the potential outcome in a world where it is absent. Were we able to observe that a person was sick in a world where they took the pill *and* sick in a world where they didn't, for example, we would infer that the pill did not have any causal effect on their health.

The problem is we can never observe our world in two counterfactual states at once, and so we can never estimate the effect of a cause on any particular individual person or thing. We can, however, estimate an *average* of individual causal effects, which we refer to as the average treatment effect (ATE). The simplest design for inferring an ATE is the two-arm experiment: some people are assigned at random to a treatment (the first arm), and the rest are assigned to the control (the second arm). The difference in the averages of the two groups gives us an unbiased estimate of the true ATE.

How does this design work? One way to think about it is to compare the random assignment of the treatment to a random sampling procedure: in this design it is as though we take a representative sample from the two counterfactual states of the world. Seen in this way, the treatment and control groups are 'random samples' from the potential outcomes in a world where the cause is present and one in which it is absent. By taking the mean of the group that represents the treated potential outcomes and comparing it to the mean of the group that represents the untreated potential outcomes, we can construct a representative guess of the true average difference in the two states of the world. Just like in random sampling, as the size of our experiment grows our guess of the ATE will converge to the true ATE, implying that our design is unbiased. As we shall see, however, characterizing our uncertainty about our guesses can be complicated, even in such a simple design.

## Design Declaration

- **M**odel:

Our model of the world specifies a population of $N$ units that have a control potential outcome, $Y_i(Z = 0)$, that is distributed standard normally. A unit's individual treatment effect is a random draw from a distribution with mean $\tau$ and standard deviation $\sigma$, that is added to its control potential outcome: $Y_i(Z = 1) = Y_i(Z = 0) + t_i$. This implies that the variance of the sample's treated potential outcomes is higher than the variance of their control potential outcomes, although they are correlated because the treated potential outcome is created by simply adding the treatment effect to the control potential outcome.

- **I**nquiry:

We want to know the average of all units' differences in treated and untreated potential outcomes -- the average treatment effect: $E[Y_i(Z = 1) - Y_i(Z = 0)] = E[t_i] = \tau$.

- **D**ata strategy:

We randomly sample $n$ units from the population of $N$. We randomly assign a fixed number, $m$, to treatment, and the rest of the $n-m$ units to control.

- **A**nswer strategy:

We subtract the mean of the control group from the mean of the treatment group in order to estimate the average treatment effect.


```{r, code = get_design_code(simple_two_arm_designer()), eval=TRUE}
```


```{r}
diagnosis <- diagnose_design(simple_two_arm_design)
```

```{r,eval = TRUE, echo = FALSE}
kable(reshape_diagnosis(diagnosis)[,-c(1,2,3,5)], digits = 2)
```

- As the diagnosis reveals, the estimate of the ATE is unbiased, but our coverage is above what it should be (95\%). This reflects the fact that conventional estimators of the standard error for the difference in means make conservative assumptions about the true covariance in potential outcomes, and thus tend to produce confidence intervals that are too wide. In other words, while the estimate of the difference in outcomes is unbiased, our estimate of the variation in this difference is biased upwards.


## Using the Simple Two Arm Designer

In R, you can generate a simple two arm design using the template function `simple_two_arm_designer()` in the `DesignLibrary` package by running the following lines, which load the package:

```{r, eval=FALSE}
library(DesignLibrary)
```

We can then create specific designs by defining values for each argument. For example, we can create a design called `my_simple_two_arm_design` where `N`, `prob`, and `ate` set to 500, .5, and .4, respectively, and other parameters use default values. To do so, we run the lines below.

```{r, eval=FALSE}
simple_two_arm_design <- simple_two_arm_designer(N = 500, prob = .5, ate = .4)
```

You can see more details on the `simple_two_arm_designer()` function, its arguments, and default values, by running the following line of code:

```{r, eval=FALSE}
??simple_two_arm_designer
```





















0 comments on commit a61bb8f

Please sign in to comment.