Skip to content

Commit edf8507

Browse files
committed
Upload Causal IV case study in education folder
1 parent a4cf8b7 commit edf8507

File tree

7 files changed

+4112
-0
lines changed

7 files changed

+4112
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

education/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
data {
2+
int<lower=1> N; // Sample size N
3+
int<lower=0,upper=1> Z[N]; // Treatment assigned Z
4+
int<lower=0,upper=1> W[N]; // Treatment received W
5+
int<lower=0,upper=1> Y[N]; // Outcome Y
6+
}
7+
8+
parameters {
9+
// Population probability of being a complier
10+
real<lower=0,upper=1> pi_c;
11+
12+
// Probabilities for the binomial outcome distributions
13+
real<lower=0,upper=1> eta_c0;
14+
real<lower=0,upper=1> eta_c1;
15+
real<lower=0,upper=1> eta_n;
16+
}
17+
18+
transformed parameters {
19+
// Superpopulation complier average causal effect (CACE)
20+
// in per-1000 units
21+
real CACE;
22+
CACE = (eta_c1 - eta_c0)*10^3;
23+
}
24+
25+
model {
26+
// Prior for Complier probability
27+
// implicit prior: pi_c ~ Unif(0, 1)
28+
29+
// Priors for outcome model parameters
30+
eta_c0 ~ beta(2, 2);
31+
eta_c1 ~ beta(2, 2);
32+
eta_n ~ beta(2, 2);
33+
34+
// Likelihood
35+
for(n in 1:N){
36+
37+
// Complier (assigned to treatment)
38+
if(Z[n] == 1 && W[n] == 1){
39+
target += log(pi_c) + bernoulli_lpmf(Y[n] | eta_c1) ;
40+
}
41+
42+
// Never-taker (assigned to treatment)
43+
else if(Z[n] == 1 && W[n] == 0){
44+
target += log(1 - pi_c) + bernoulli_lpmf(Y[n] | eta_n);
45+
}
46+
47+
// Complier or Never-taker (assigned to control)
48+
else if(Z[n] == 0 && W[n] == 0){
49+
target += log_sum_exp(
50+
log(1 - pi_c) + bernoulli_lpmf(Y[n] | eta_n), // Never-taker
51+
log(pi_c) + bernoulli_lpmf(Y[n] | eta_c0)); // Complier
52+
}
53+
}
54+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
data {
2+
int<lower=1> N; // Sample size N
3+
int<lower=0,upper=1> Z[N]; // Treatment assigned Z
4+
int<lower=0,upper=1> W[N]; // Treatment received W
5+
int<lower=0,upper=1> Y[N]; // Outcome Y
6+
}
7+
8+
parameters {
9+
// Population probability of being a complier
10+
real<lower=0,upper=1> pi_c;
11+
12+
// Probabilities for the binomial outcome distributions
13+
real<lower=0,upper=1> eta_c0;
14+
real<lower=0,upper=1> eta_c1;
15+
real<lower=0,upper=1> eta_n0;
16+
real<lower=0,upper=1> eta_n1;
17+
}
18+
19+
transformed parameters {
20+
// Super-population average causal effects
21+
real CACE;
22+
real NACE;
23+
CACE = (eta_c1 - eta_c0)*10^3;
24+
NACE = (eta_n1 - eta_n0)*10^3;
25+
}
26+
27+
model {
28+
// Prior for Complier probability
29+
// implicit prior: pi_c ~ Unif(0, 1)
30+
31+
// Priors for outcome model parameters
32+
eta_c0 ~ beta(2, 2);
33+
eta_c1 ~ beta(2, 2);
34+
eta_n0 ~ beta(2, 2);
35+
eta_n1 ~ beta(2, 2);
36+
37+
// Likelihood
38+
for(n in 1:N){
39+
40+
// Complier (assigned to treatment)
41+
if(Z[n] == 1 && W[n] == 1){
42+
target += log(pi_c) + bernoulli_lpmf(Y[n] | eta_c1) ;
43+
}
44+
45+
// Never-taker (assigned to treatment)
46+
else if(Z[n] == 1 && W[n] == 0){
47+
target += log(1 - pi_c) + bernoulli_lpmf(Y[n] | eta_n1);
48+
}
49+
50+
// Complier or Never-taker (assigned to control)
51+
else if(Z[n] == 0 && W[n] == 0){
52+
target += log_sum_exp(
53+
log(1 - pi_c) + bernoulli_lpmf(Y[n] | eta_n0), // Never-taker
54+
log(pi_c) + bernoulli_lpmf(Y[n] | eta_c0)); // Complier
55+
}
56+
}
57+
}

education/causal_iv_one-sided/case_study_02_IV_one-sided.html

Lines changed: 3387 additions & 0 deletions
Large diffs are not rendered by default.

education/causal_iv_one-sided/case_study_02_IV_one-sided.qmd

Lines changed: 555 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@book{imbens2015causal,
2+
title={Causal inference in statistics, social, and biomedical sciences},
3+
author={Imbens, Guido W and Rubin, Donald B},
4+
year={2015},
5+
publisher={Cambridge University Press}
6+
}
7+
8+
@article{imbens1997bayesian,
9+
title={Bayesian inference for causal effects in randomized experiments with noncompliance},
10+
author={Imbens, Guido W and Rubin, Donald B},
11+
journal={The annals of statistics},
12+
pages={305--327},
13+
year={1997},
14+
publisher={JSTOR}
15+
}
16+
17+
@article{sommer1991estimating,
18+
title={On estimating efficacy from clinical trials},
19+
author={Sommer, Alfred and Zeger, Scott L},
20+
journal={Statistics in medicine},
21+
volume={10},
22+
number={1},
23+
pages={45--52},
24+
year={1991},
25+
publisher={Wiley Online Library}
26+
}
27+
28+
@article{feller2016compared,
29+
title={Compared to what? Variation in the impacts of early childhood education by alternative care type},
30+
author={Feller, Avi and Grindal, Todd and Miratrix, Luke and Page, Lindsay C and others},
31+
journal={The Annals of Applied Statistics},
32+
volume={10},
33+
number={3},
34+
pages={1245--1285},
35+
year={2016},
36+
publisher={Institute of Mathematical Statistics}
37+
}
38+
39+
@article{page2015principal,
40+
title={Principal stratification: A tool for understanding variation in program effects across endogenous subgroups},
41+
author={Page, Lindsay C and Feller, Avi and Grindal, Todd and Miratrix, Luke and Somers, Marie-Andree},
42+
journal={American Journal of Evaluation},
43+
volume={36},
44+
number={4},
45+
pages={514--531},
46+
year={2015},
47+
publisher={Sage Publications Sage CA: Los Angeles, CA}
48+
}
49+
50+
@article{gelman1992inference,
51+
title={Inference from iterative simulation using multiple sequences},
52+
author={Gelman, Andrew and Rubin, Donald B and others},
53+
journal={Statistical science},
54+
volume={7},
55+
number={4},
56+
pages={457--472},
57+
year={1992},
58+
publisher={Institute of Mathematical Statistics}
59+
}

0 commit comments

Comments
 (0)