Skip to content

Commit f73317a

Browse files
Merge pull request #219 from joonho112/master
Upload Causal IV case study in education folder
2 parents ef7fe3d + 0e9cd1f commit f73317a

File tree

7 files changed

+4803
-0
lines changed

7 files changed

+4803
-0
lines changed

.DS_Store

-6 KB
Binary file not shown.

education/.DS_Store

-6 KB
Binary file not shown.

education/causal_iv_one-sided/case_study_02_IV_one-sided.html

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

education/causal_iv_one-sided/case_study_02_IV_one-sided.qmd

Lines changed: 585 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+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
data {
2+
int<lower=1> N; // Sample size N
3+
array[N] int<lower=0, upper=1> Z; // Treatment assigned Z
4+
array[N] int<lower=0, upper=1> W; // Treatment received W
5+
array[N] int<lower=0, upper=1> Y; // 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+
model {
19+
// Define local variables for efficiency
20+
real log_pi_c = log(pi_c);
21+
real log1m_pi_c = log1m(pi_c);
22+
23+
// Prior for Complier probability
24+
// implicit prior: pi_c ~ Unif(0, 1)
25+
26+
// Priors for outcome model parameters
27+
eta_c0 ~ beta(2, 2);
28+
eta_c1 ~ beta(2, 2);
29+
eta_n ~ beta(2, 2);
30+
31+
// Likelihood
32+
for(n in 1:N){
33+
34+
// Complier (assigned to treatment)
35+
if (Z[n] == 1 && W[n] == 1){
36+
target += log_pi_c + bernoulli_lpmf(Y[n] | eta_c1) ;
37+
}
38+
39+
// Never-taker (assigned to treatment)
40+
else if (Z[n] == 1 && W[n] == 0){
41+
target += log1m_pi_c + bernoulli_lpmf(Y[n] | eta_n);
42+
}
43+
44+
// Complier or Never-taker (assigned to control)
45+
else if (Z[n] == 0 && W[n] == 0){
46+
target += log_mix(
47+
pi_c, // Complier probability
48+
bernoulli_lpmf(Y[n] | eta_c0), // Complier
49+
bernoulli_lpmf(Y[n] | eta_n) // Never-taker
50+
);
51+
}
52+
}
53+
}
54+
55+
generated quantities {
56+
// Superpopulation complier average causal effect (CACE)
57+
// in per-1000 units
58+
real CACE = (eta_c1 - eta_c0) * 10^3;
59+
}
60+
61+
62+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
data {
2+
int<lower=1> N; // Sample size N
3+
array[N] int<lower=0, upper=1> Z; // Treatment assigned Z
4+
array[N] int<lower=0, upper=1> W; // Treatment received W
5+
array[N] int<lower=0, upper=1> Y; // 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+
model {
20+
// Define local variables for efficiency
21+
real log_pi_c = log(pi_c);
22+
real log1m_pi_c = log1m(pi_c);
23+
24+
// Prior for Complier probability
25+
// implicit prior: pi_c ~ Unif(0, 1)
26+
27+
// Priors for outcome model parameters
28+
eta_c0 ~ beta(2, 2);
29+
eta_c1 ~ beta(2, 2);
30+
eta_n0 ~ beta(2, 2);
31+
eta_n1 ~ beta(2, 2);
32+
33+
// Likelihood
34+
for(n in 1:N){
35+
36+
// Complier (assigned to treatment)
37+
if (Z[n] == 1 && W[n] == 1){
38+
target += log_pi_c + bernoulli_lpmf(Y[n] | eta_c1) ;
39+
}
40+
41+
// Never-taker (assigned to treatment)
42+
else if (Z[n] == 1 && W[n] == 0){
43+
target += log1m_pi_c + bernoulli_lpmf(Y[n] | eta_n1);
44+
}
45+
46+
// Complier or Never-taker (assigned to control)
47+
else if (Z[n] == 0 && W[n] == 0){
48+
target += log_mix(
49+
pi_c, // Complier probability
50+
bernoulli_lpmf(Y[n] | eta_c0), // Complier
51+
bernoulli_lpmf(Y[n] | eta_n0) // Never-taker
52+
);
53+
}
54+
}
55+
}
56+
57+
generated quantities {
58+
// Super-population average causal effects
59+
real CACE = (eta_c1 - eta_c0) * 10^3;
60+
real NACE = (eta_n1 - eta_n0) * 10^3;
61+
}
62+
63+

0 commit comments

Comments
 (0)