-
-
Notifications
You must be signed in to change notification settings - Fork 478
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
edf8507
Upload Causal IV case study in education folder
joonho112 4ffcfdf
updated stan code
joonho112 33beccb
Deleted .DS_Store
joonho112 26cb940
updated using new array syntax
joonho112 0e9cd1f
Updated generated quantities block
joonho112 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
4,034 changes: 4,034 additions & 0 deletions
4,034
education/causal_iv_one-sided/case_study_02_IV_one-sided.html
Large diffs are not rendered by default.
Oops, something went wrong.
572 changes: 572 additions & 0 deletions
572
education/causal_iv_one-sided/case_study_02_IV_one-sided.qmd
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
education/causal_iv_one-sided/stan/cace_with_exclusion.stan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
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
62
education/causal_iv_one-sided/stan/cace_without_exclusion.stan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to |
||
} | ||
|
||
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 | ||
); | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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