InversePropensityWeighting#
- class causalpy.experiments.inverse_propensity_weighting.InversePropensityWeighting[source]#
A class to analyse inverse propensity weighting experiments.
- Parameters:
data (
NativeDataFrame) – Any eager dataframe Narwhals supports, such as pandas, Polars, or PyArrow. Converted to pandas internally.formula (
str) – A statistical model formula for the propensity model.outcome_variable (
str) – A string denoting the outcome variable in data to be reweighted.weighting_scheme (
str) – A string denoting which weighting scheme to use among: ‘raw’, ‘robust’, ‘doubly_robust’ or ‘overlap’. See Aronow and Miller “Foundations of Agnostic Statistics” for discussion and computation of these weighting schemes.model (
PropensityScore|None) – A PyMC model. Defaults to PropensityScore.
Notes
Estimate extraction
Fitting produces posterior propensity-score draws.
get_ate()post-processes one draw at a time:"raw"and"robust"contrast inverse-probability-weighted mean outcomes for the treated and control potential outcomes,"overlap"contrasts overlap-weighted means for the overlap population, and"doubly_robust"augments inverse-probability weighting with separate OLS outcome regressions before averaging over all observations.Examples
>>> import causalpy as cp >>> df = cp.load_data("nhefs") >>> seed = 42 >>> result = cp.InversePropensityWeighting( ... df, ... formula="trt ~ 1 + age + race", ... outcome_variable="outcome", ... weighting_scheme="robust", ... model=cp.pymc_models.PropensityScore( ... sample_kwargs={ ... "draws": 100, ... "target_accept": 0.95, ... "random_seed": seed, ... "progressbar": False, ... }, ... ), ... )
Methods
Run the experiment algorithm by fitting the propensity score model.
Raise because unified effect summaries are unavailable.
Generate a self-contained HTML report for this experiment.
InversePropensityWeighting.get_ate(i, idata)Compute the Average Treatment Effect for a single posterior sample.
Validate the input data and model formula for correctness.
InversePropensityWeighting.make_doubly_robust_adjustment(ps)Compute doubly-robust adjusted outcomes.
Compute inverse-propensity-weighted outcomes using the overlap scheme.
Compute inverse-propensity-weighted outcomes using the raw (basic) scheme.
Compute inverse-propensity-weighted outcomes using the robust (Horvitz-Thompson) scheme.
InversePropensityWeighting.plot(*[, show, ...])Plot the results.
InversePropensityWeighting.plot_ate([idata, ...])Plot the Average Treatment Effect and propensity score distributions.
Plot the empirical CDF of a covariate before and after IPW adjustment.
Ask the model to print its coefficients.
Set optional maketables rendering options for this experiment.
Compute a weighted percentile of the data.
Attributes
idataReturn fitted DataTree when the model backend supports it.
supports_bayessupports_olssupports_pymc_forecastlabelsdata- __init__(data, formula, outcome_variable, weighting_scheme, model=None)[source]#
- Parameters:
data (DataFrameLike)
formula (str)
outcome_variable (str)
weighting_scheme (str)
model (PropensityScore | None)
- Return type:
None
- classmethod __new__(*args, **kwargs)#