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

:param outcome_variable

A string denoting the outcome variable in datq to be reweighted

Parameters:
  • 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 – A PyMC model

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.bayesian_plot(...)

Abstract method for plotting the model.

InversePropensityWeighting.get_ate(i, idata)

InversePropensityWeighting.input_validation()

Validate the input data and model formula for correctness

InversePropensityWeighting.make_doubly_robust_adjustment(ps)

The doubly robust weighting scheme is also discussed in Aronow and Miller, but a bit more generally than our implementation here.

InversePropensityWeighting.make_overlap_adjustments(ps)

This weighting scheme was adapted from Lucy D’Agostino McGowan's blog on Propensity Score Weights referenced in the primary CausalPy explainer notebook

InversePropensityWeighting.make_raw_adjustments(ps)

This estimator is discussed in Aronow and Miller as the simplest of base form of inverse propensity weighting schemes

InversePropensityWeighting.make_robust_adjustments(ps)

This estimator is discussed in Aronow and Miller's book as being related to the Horvitz Thompson method

InversePropensityWeighting.ols_plot(*args, ...)

Abstract method for plotting the model.

InversePropensityWeighting.plot(*args, **kwargs)

Plot the model.

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

InversePropensityWeighting.plot_balance_ecdf(...)

Plotting function takes a single covariate and shows the differences in the ECDF between the treatment and control groups before and after weighting.

InversePropensityWeighting.print_coefficients([...])

Ask the model to print its coefficients.

InversePropensityWeighting.weighted_percentile(...)

perc : percentile in [0-1]!

Attributes

idata

Return the InferenceData object of the model.

supports_bayes

supports_ols

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