InversePropensityWeighting#

class causalpy.experiments.inverse_propensity_weighting.InversePropensityWeighting[source]#

A class to analyse inverse propensity weighting experiments.

Parameters:
  • data (DataFrame) – A pandas dataframe.

  • 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.

Example

>>> 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

InversePropensityWeighting.__init__(data, ...)

InversePropensityWeighting.algorithm()

Run the experiment algorithm by fitting the propensity score model.

InversePropensityWeighting.effect_summary(*)

Generate a decision-ready summary of causal effects.

InversePropensityWeighting.fit(*args, **kwargs)

InversePropensityWeighting.generate_report(*)

Generate a self-contained HTML report for this experiment.

InversePropensityWeighting.get_ate(i, idata)

Compute the Average Treatment Effect for a single posterior sample.

InversePropensityWeighting.get_plot_data(...)

Recover the data of an experiment along with the prediction and causal impact information.

InversePropensityWeighting.get_plot_data_bayesian(...)

Return plot data for Bayesian models.

InversePropensityWeighting.get_plot_data_ols(...)

Return plot data for OLS models.

InversePropensityWeighting.input_validation()

Validate the input data and model formula for correctness.

InversePropensityWeighting.make_doubly_robust_adjustment(ps)

Compute doubly-robust adjusted outcomes.

InversePropensityWeighting.make_overlap_adjustments(ps)

Compute inverse-propensity-weighted outcomes using the overlap scheme.

InversePropensityWeighting.make_raw_adjustments(ps)

Compute inverse-propensity-weighted outcomes using the raw (basic) scheme.

InversePropensityWeighting.make_robust_adjustments(ps)

Compute inverse-propensity-weighted outcomes using the robust (Horvitz-Thompson) scheme.

InversePropensityWeighting.plot(*args[, show])

Plot the model.

InversePropensityWeighting.plot_ate([idata, ...])

Plot the Average Treatment Effect and propensity score distributions.

InversePropensityWeighting.plot_balance_ecdf(...)

Plot the empirical CDF of a covariate before and after IPW adjustment.

InversePropensityWeighting.print_coefficients([...])

Ask the model to print its coefficients.

InversePropensityWeighting.set_maketables_options(*)

Set optional maketables rendering options for this experiment.

InversePropensityWeighting.weighted_percentile(...)

Compute a weighted percentile of the data.

Attributes

idata

Return the InferenceData object of the model.

supports_bayes

supports_ols

labels

data

__init__(data, formula, outcome_variable, weighting_scheme, model=None, **kwargs)[source]#
Parameters:
Return type:

None

classmethod __new__(*args, **kwargs)#