Skip to content

Commit ae451cd

Browse files
committed
add winsorisation option and better priors for nhefs
Signed-off-by: Nathaniel <NathanielF@users.noreply.github.com>
1 parent 05fccdd commit ae451cd

File tree

2 files changed

+830
-857
lines changed

2 files changed

+830
-857
lines changed

causalpy/pymc_models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,13 @@ def fit_outcome_model(
613613
coords,
614614
priors={
615615
"b_outcome": [0, 1],
616-
"a_outcome": [0, 1],
617616
"sigma": 1,
618617
"beta_ps": [0, 1],
619618
},
620619
noncentred=True,
621620
normal_outcome=True,
622621
spline_component=False,
622+
winsorize_boundary=0.0,
623623
):
624624
"""
625625
Fit a Bayesian outcome model using covariates and previously estimated propensity scores.
@@ -643,7 +643,6 @@ def fit_outcome_model(
643643
priors : dict, optional
644644
Dictionary specifying priors for outcome model parameters:
645645
- "b_outcome": list [mean, std] for regression coefficients.
646-
- "a_outcome": list [mean, std] for the intercept.
647646
- "sigma": standard deviation of the outcome noise (default 1).
648647
649648
noncentred : bool, default True
@@ -657,6 +656,10 @@ def fit_outcome_model(
657656
If True, include a spline basis expansion on the propensity score to allow
658657
flexible (nonlinear) adjustment. Uses B-splines with 30 internal knots.
659658
659+
winsorize_boundary : float, default 0.0
660+
If we wish to winsorize the propensity score this can be set to clip the high
661+
and low values of the propensity at 0 + winsorize_boundary and 1-winsorize_boundary
662+
660663
Returns
661664
-------
662665
idata_outcome : arviz.InferenceData
@@ -677,8 +680,8 @@ def fit_outcome_model(
677680
posterior of the treatment model, randomly selecting one posterior draw
678681
per call. This term is estimated initially in the InversePropensity
679682
class initialisation.
680-
- The term `beta_ps[0] * p + beta_ps[1] * (p * treatment)` captures both
681-
main and interaction effects of the propensity score.
683+
- The term `beta_ps[0] * p` captures both
684+
main effects of the propensity score.
682685
- Including spline adjustment enables modeling nonlinear relationships
683686
between the propensity score and the outcome.
684687
@@ -711,6 +714,7 @@ class initialisation.
711714

712715
chosen = np.random.choice(range(propensity_scores.shape[1]))
713716
p = propensity_scores[:, chosen].values
717+
p = np.clip(p, winsorize_boundary, 1 - winsorize_boundary)
714718

715719
mu_outcome = pm.math.dot(X_data_outcome, beta) + beta_ps * p
716720

0 commit comments

Comments
 (0)