Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Causal IV case study in education folder #219

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
Binary file removed education/.DS_Store
Binary file not shown.
4,034 changes: 4,034 additions & 0 deletions education/causal_iv_one-sided/case_study_02_IV_one-sided.html

Large diffs are not rendered by default.

572 changes: 572 additions & 0 deletions education/causal_iv_one-sided/case_study_02_IV_one-sided.qmd

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions education/causal_iv_one-sided/references.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@book{imbens2015causal,
title={Causal inference in statistics, social, and biomedical sciences},
author={Imbens, Guido W and Rubin, Donald B},
year={2015},
publisher={Cambridge University Press}
}

@article{imbens1997bayesian,
title={Bayesian inference for causal effects in randomized experiments with noncompliance},
author={Imbens, Guido W and Rubin, Donald B},
journal={The annals of statistics},
pages={305--327},
year={1997},
publisher={JSTOR}
}

@article{sommer1991estimating,
title={On estimating efficacy from clinical trials},
author={Sommer, Alfred and Zeger, Scott L},
journal={Statistics in medicine},
volume={10},
number={1},
pages={45--52},
year={1991},
publisher={Wiley Online Library}
}

@article{feller2016compared,
title={Compared to what? Variation in the impacts of early childhood education by alternative care type},
author={Feller, Avi and Grindal, Todd and Miratrix, Luke and Page, Lindsay C and others},
journal={The Annals of Applied Statistics},
volume={10},
number={3},
pages={1245--1285},
year={2016},
publisher={Institute of Mathematical Statistics}
}

@article{page2015principal,
title={Principal stratification: A tool for understanding variation in program effects across endogenous subgroups},
author={Page, Lindsay C and Feller, Avi and Grindal, Todd and Miratrix, Luke and Somers, Marie-Andree},
journal={American Journal of Evaluation},
volume={36},
number={4},
pages={514--531},
year={2015},
publisher={Sage Publications Sage CA: Los Angeles, CA}
}

@article{gelman1992inference,
title={Inference from iterative simulation using multiple sequences},
author={Gelman, Andrew and Rubin, Donald B and others},
journal={Statistical science},
volume={7},
number={4},
pages={457--472},
year={1992},
publisher={Institute of Mathematical Statistics}
}
60 changes: 60 additions & 0 deletions education/causal_iv_one-sided/stan/cace_with_exclusion.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
data {
int<lower=1> N; // Sample size N
array[N] int<lower=0, upper=1> Z; // Treatment assigned Z
array[N] int<lower=0, upper=1> W; // Treatment received W
array[N] int<lower=0, upper=1> Y; // Outcome Y
}

parameters {
// Population probability of being a complier
real<lower=0, upper=1> pi_c;

// Probabilities for the binomial outcome distributions
real<lower=0, upper=1> eta_c0;
real<lower=0, upper=1> eta_c1;
real<lower=0, upper=1> eta_n;
}

transformed parameters {
// Superpopulation complier average causal effect (CACE)
// in per-1000 units
real CACE = (eta_c1 - eta_c0) * 10^3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to generated quantities block

}

model {
// Define local variables for efficiency
real log_pi_c = log(pi_c);
real log1m_pi_c = log1m(pi_c);

// Prior for Complier probability
// implicit prior: pi_c ~ Unif(0, 1)

// Priors for outcome model parameters
eta_c0 ~ beta(2, 2);
eta_c1 ~ beta(2, 2);
eta_n ~ beta(2, 2);

// Likelihood
for(n in 1:N){

// Complier (assigned to treatment)
if (Z[n] == 1 && W[n] == 1){
target += log_pi_c + bernoulli_lpmf(Y[n] | eta_c1) ;
}

// Never-taker (assigned to treatment)
else if (Z[n] == 1 && W[n] == 0){
target += log1m_pi_c + bernoulli_lpmf(Y[n] | eta_n);
}

// Complier or Never-taker (assigned to control)
else if (Z[n] == 0 && W[n] == 0){
target += log_mix(
pi_c, // Complier probability
bernoulli_lpmf(Y[n] | eta_c0), // Complier
bernoulli_lpmf(Y[n] | eta_n) // Never-taker
);
}
}
}

62 changes: 62 additions & 0 deletions education/causal_iv_one-sided/stan/cace_without_exclusion.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
data {
int<lower=1> N; // Sample size N
array[N] int<lower=0, upper=1> Z; // Treatment assigned Z
array[N] int<lower=0, upper=1> W; // Treatment received W
array[N] int<lower=0, upper=1> Y; // Outcome Y
}

parameters {
// Population probability of being a complier
real<lower=0, upper=1> pi_c;

// Probabilities for the binomial outcome distributions
real<lower=0, upper=1> eta_c0;
real<lower=0, upper=1> eta_c1;
real<lower=0, upper=1> eta_n0;
real<lower=0, upper=1> eta_n1;
}

transformed parameters {
// Super-population average causal effects
real CACE = (eta_c1 - eta_c0) * 10^3;
real NACE = (eta_n1 - eta_n0) * 10^3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to generated quantities block

}

model {
// Define local variables for efficiency
real log_pi_c = log(pi_c);
real log1m_pi_c = log1m(pi_c);

// Prior for Complier probability
// implicit prior: pi_c ~ Unif(0, 1)

// Priors for outcome model parameters
eta_c0 ~ beta(2, 2);
eta_c1 ~ beta(2, 2);
eta_n0 ~ beta(2, 2);
eta_n1 ~ beta(2, 2);

// Likelihood
for(n in 1:N){

// Complier (assigned to treatment)
if (Z[n] == 1 && W[n] == 1){
target += log_pi_c + bernoulli_lpmf(Y[n] | eta_c1) ;
}

// Never-taker (assigned to treatment)
else if (Z[n] == 1 && W[n] == 0){
target += log1m_pi_c + bernoulli_lpmf(Y[n] | eta_n1);
}

// Complier or Never-taker (assigned to control)
else if (Z[n] == 0 && W[n] == 0){
target += log_mix(
pi_c, // Complier probability
bernoulli_lpmf(Y[n] | eta_c0), // Complier
bernoulli_lpmf(Y[n] | eta_n0) // Never-taker
);
}
}
}