Skip to content

Commit a38e50a

Browse files
committed
update with Ben and Alex's feedback
Signed-off-by: Nathaniel <[email protected]>
1 parent 9f6a025 commit a38e50a

File tree

4 files changed

+141
-71
lines changed

4 files changed

+141
-71
lines changed

causalpy/data_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _input_validation(self):
136136

137137

138138
class PropensityDataValidator:
139-
"""Mixin class for validating the input data and model formula for IV experiments."""
139+
"""Mixin class for validating the input data and model formula for Propensity Weighting experiments."""
140140

141141
def _input_validation(self):
142142
"""Validate the input data and model formula for correctness"""

causalpy/pymc_experiments.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,9 @@ class InversePropensityWeighting(ExperimentalDesign, PropensityDataValidator):
14941494
A string denoting the outcome variable in datq to be reweighted
14951495
:param weighting_scheme:
14961496
A string denoting which weighting scheme to use among: 'raw', 'robust',
1497-
'doubly robust'
1497+
'doubly robust' or 'overlap'. See Aronow and Miller "Foundations
1498+
of Agnostic Statistics" for discussion and computation of these
1499+
weighting schemes.
14981500
:param model:
14991501
A PyMC model
15001502
@@ -1548,6 +1550,9 @@ def __init__(
15481550
self.model.fit(X=self.X, t=self.t, coords=COORDS)
15491551

15501552
def make_robust_adjustments(self, ps):
1553+
""" This estimator is discussed in Aronow
1554+
and Miller's book as being related to the
1555+
Horvitz Thompson method """
15511556
X = pd.DataFrame(self.X, columns=self.labels)
15521557
X["ps"] = ps
15531558
X[self.outcome_variable] = self.y
@@ -1565,6 +1570,9 @@ def make_robust_adjustments(self, ps):
15651570
return weighted_outcome0, weighted_outcome1, n_ntrt, n_trt
15661571

15671572
def make_raw_adjustments(self, ps):
1573+
""" This estimator is discussed in Aronow and
1574+
Miller as the simplest of base form of
1575+
inverse propensity weighting schemes"""
15681576
X = pd.DataFrame(self.X, columns=self.labels)
15691577
X["ps"] = ps
15701578
X[self.outcome_variable] = self.y
@@ -1581,6 +1589,10 @@ def make_raw_adjustments(self, ps):
15811589
return weighted_outcome0, weighted_outcome1, n_ntrt, n_trt
15821590

15831591
def make_overlap_adjustments(self, ps):
1592+
"""This weighting scheme was adapted from
1593+
Lucy D’Agostino McGowan's blog on
1594+
Propensity Score Weights referenced in
1595+
the primary CausalPy explainer notebook"""
15841596
X = pd.DataFrame(self.X, columns=self.labels)
15851597
X["ps"] = ps
15861598
X[self.outcome_variable] = self.y
@@ -1597,6 +1609,12 @@ def make_overlap_adjustments(self, ps):
15971609
return weighted_outcome0, weighted_outcome1, n_ntrt, n_trt
15981610

15991611
def make_doubly_robust_adjustment(self, ps):
1612+
""" The doubly robust weighting scheme is also
1613+
discussed in Aronow and Miller, but a bit more generally
1614+
than our implementation here. Here we have specified
1615+
the outcome model to be a simple OLS model.
1616+
In this way the compromise between the outcome model and
1617+
the propensity model is always done with OLS."""
16001618
X = pd.DataFrame(self.X, columns=self.labels)
16011619
X["ps"] = ps
16021620
t = self.t.flatten()
@@ -1722,8 +1740,9 @@ def make_hists(idata, i, axs, method=method):
17221740
0.9, linestyle="--", label="Hi Extreme Propensity Scores", color="black"
17231741
)
17241742
axs[0].set_title(
1725-
"Draws from the Posterior \n Propensity Scores Distribution", fontsize=20
1743+
"Weighted and Unweighted Draws from the Posterior \n Propensity Scores Distribution", fontsize=20
17261744
)
1745+
axs[0].set_ylabel("Counts of Observations")
17271746
axs[0].set_xlabel("Propensity Scores")
17281747
custom_lines = [
17291748
Line2D([0], [0], color="skyblue", lw=2),

docs/source/notebooks/inv_prop_pymc.ipynb

Lines changed: 103 additions & 68 deletions
Large diffs are not rendered by default.

docs/source/references.bib

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ @book{hansenEconometrics
5959
publisher={Princeton}
6060
}
6161

62+
@book{aronowFoundations,
63+
author={Aronow, P and Miller, B},
64+
title={Foundations of Agnostic Statistics},
65+
publisher={Cambridge University Press},
66+
year={2019}
67+
}
68+
6269
@article{acemoglu2001colonial,
6370
title={The Colonial Origins of Comparative Development: An Empirical Investigation},
6471
author={Acemoglu, D and Johnson, S and Robinson, J},
@@ -68,3 +75,12 @@ @article{acemoglu2001colonial
6875
pages={1369--1401},
6976
year={2001}
7077
}
78+
79+
@incollection{forde2024nonparam,
80+
author = {Forde, Nathaniel},
81+
title = {Bayesian Non-parametric Causal Inference},
82+
editor = {PyMC Team},
83+
booktitle = {PyMC examples},
84+
doi = {10.5281/zenodo.5654871},
85+
year = {2024}
86+
}

0 commit comments

Comments
 (0)