Skip to content

Commit fcf2626

Browse files
committed
iv and multiple instruments
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
1 parent 040f20d commit fcf2626

File tree

7 files changed

+6614
-6
lines changed

7 files changed

+6614
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ repos:
2222
exclude_types: [svg]
2323
- id: check-yaml
2424
- id: check-added-large-files
25+
exclude: &exclude_pattern 'iv_weak_instruments.ipynb'
2526
args: ["--maxkb=1500"]
2627
- repo: https://github.com/astral-sh/ruff-pre-commit
2728
rev: v0.4.4

causalpy/data/datasets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"geolift1": {"filename": "geolift1.csv"},
3636
"risk": {"filename": "AJR2001.csv"},
3737
"nhefs": {"filename": "nhefs.csv"},
38+
"schoolReturns": {"filename": "schoolingReturns.csv"},
3839
}
3940

4041

causalpy/data/schoolingReturns.csv

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

causalpy/pymc_models.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,27 @@ def build_model(self, X, Z, y, t, coords, priors):
376376
shape=(X.shape[0], 2),
377377
)
378378

379-
def fit(self, X, Z, y, t, coords, priors):
379+
def fit(self, X, Z, y, t, coords, priors, sample_ppc=True):
380380
"""Draw samples from posterior, prior predictive, and posterior predictive
381381
distributions.
382382
"""
383383

384384
# Ensure random_seed is used in sample_prior_predictive() and
385385
# sample_posterior_predictive() if provided in sample_kwargs.
386+
# Use JAX for ppc sampling of multivariate likelihood
386387
random_seed = self.sample_kwargs.get("random_seed", None)
387388

388389
self.build_model(X, Z, y, t, coords, priors)
389390
with self:
390391
self.idata = pm.sample(**self.sample_kwargs)
391-
self.idata.extend(pm.sample_prior_predictive(random_seed=random_seed))
392-
self.idata.extend(
393-
pm.sample_posterior_predictive(
394-
self.idata, progressbar=False, random_seed=random_seed
392+
if sample_ppc:
393+
self.idata.extend(
394+
pm.sample_posterior_predictive(
395+
self.idata,
396+
random_seed=random_seed,
397+
compile_kwargs={"mode": "JAX"},
398+
)
395399
)
396-
)
397400
return self.idata
398401

399402

docs/source/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Instrumental Variables Regression
6868
:titlesonly:
6969

7070
notebooks/iv_pymc.ipynb
71+
notebooks/iv_weak_instruments.ipynb
7172

7273
Inverse Propensity Score Weighting
7374
=================================

docs/source/notebooks/iv_weak_instruments.ipynb

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

docs/source/references.bib

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ @article{acemoglu2001colonial
7676
year={2001}
7777
}
7878

79+
@incollection{card1995returns,
80+
author={Card, David},
81+
title={Using Geographical Variation in College Proximity to Estimate the Return to Schooling},
82+
editor={Christofides, L.N. and Grant, E.K. and Swidinsky, R.},
83+
booktitle={Aspects of Labour Market Behaviour: Essays in Honour of John Vanderkamp},
84+
year={1995},
85+
publisher={University of Toronto Press}
86+
}
87+
7988
@incollection{forde2024nonparam,
8089
author = {Forde, Nathaniel},
8190
title = {Bayesian Non-parametric Causal Inference},

0 commit comments

Comments
 (0)