-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
105 lines (73 loc) · 3.87 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Gaines and Kuklinski (2011) Estimators for Hybrid Experiments
**GK2011** is a package for providing implementations of the treatment effect estimators for hybrid (self-selection) experiments, as developed by Gaines and Kuklinski (2011).
These functions estimate local average treatment effects for unobserved population subgroups inclined and disinclined to be treated, as revealed by a three-condition (two-arm) "hybrid" experimental design. In the design, participants are randomly assigned to one of three conditions: 1) treatment (T), 2) control (C), or 3) self-selection (S) of treatment or control. The design enables the estimation of four treatment effects:
1. The sample average treatment effect,
2. The effect for those inclined to choose treatment,
3. The effect for those disinclined to choose treatment (or, equivalent, to inclined to choose control), and
4. The naive difference in the outcome between those who chose treatment rather than control.
## Code Examples
The only function is `estimate()`, which provides a simple interface for estimating all effects:
```{r}
library("GK2011")
# create fake data
set.seed(12345)
d <-
data.frame(rand = c(rep(1, 200), rep(0, 100)),
tr = c(rep(0, 100), rep(1, 100), rep(0, 37), rep(1, 63)),
y = c(rnorm(100), rnorm(100) + 1, rnorm(37), rnorm(63) + 3))
# estimate effects
estimate(rand = d$rand, tr = d$tr, y = d$y)
```
The response structure is a data.frame containing the name of each effect, the effect estimate, and bootstrapped standard error.
### Gaines and Kuklinski's data
A small example dataset is included that contains treatment and outcome data from Gaines and Kuklinski's (2011) study. The following code replicate the main descriptive results from Table 2 of their paper:
```{r}
data(ajps)
pmean <- function(x) sprintf("%0.1f", mean(x))
cbind(
# Democrats
aggregate(cbind(therm.mccain, therm.obama) ~ tr, data = ajps[ajps$pid == 1, ], FUN = pmean)[, 1:3],
n_dem = aggregate(therm.obama ~ tr, data = ajps[ajps$pid == 1, ], FUN = length)[, 2],
# Republicans
aggregate(cbind(therm.mccain, therm.obama) ~ tr, data = ajps[ajps$pid == -1, ], FUN = pmean)[, 2:3],
n_rep = aggregate(therm.obama ~ tr, data = ajps[ajps$pid == -1, ], FUN = length)[, 2]
)
```
The paper reports four main sets of experimental results, separating the experiment by outcome (feeling thermometers for Obama and McCain) and by respondents' party identification (Democrats and Republicans).
Here are effects for McCain among Democrats:
```{r}
with(ajps[ajps$pid == 1, ], {
estimate(rand = tr %in% 1:2, tr = tr %in% c(1,3), y = therm.mccain)
})
```
Here are effects for McCain among Republicans:
```{r}
with(ajps[ajps$pid == -1, ], {
estimate(rand = tr %in% 1:2, tr = tr %in% c(1,3), y = therm.mccain)
})
```
Here are effects for Obama among Democrats:
```{r}
with(ajps[ajps$pid == 1, ], {
estimate(rand = tr %in% 1:2, tr = tr %in% c(1,3), y = therm.obama)
})
```
Here are effects for Obama among Republicans:
```{r}
with(ajps[ajps$pid == -1, ], {
estimate(rand = tr %in% 1:2, tr = tr %in% c(1,3), y = therm.obama)
})
```
## Installation
[![CRAN](https://www.r-pkg.org/badges/version/GK2011)](https://cran.r-project.org/package=GK2011)
[![Build Status](https://travis-ci.org/leeper/GK2011.png?branch=master)](https://travis-ci.org/leeper/GK2011)
[![codecov.io](https://codecov.io/github/leeper/GK2011/coverage.svg?branch=master)](https://codecov.io/github/leeper/GK2011?branch=master)
This package is not yet on CRAN. To install the latest development version you can pull directly from GitHub:
```R
if(!require("remotes")){
install.packages("remotes")
}
remotes::install_github("leeper/GK2011")
```
## References
Brian J. Gaines and James H. Kuklinski, (2011), "Experimental Estimation of Heterogeneous Treatment Effects Related to Self-Selection," *American Journal of Political Science* 55(3): 724-736, doi:10.1111/j.1540-5907.2011.00518.x.