InversePropensityWeighting#
- class causalpy.experiments.inverse_propensity_weighting.InversePropensityWeighting[source]#
A class to analyse inverse propensity weighting experiments.
- Parameters:
data (pd.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 (BaseExperiment, optional) – A PyMC model. Defaults to None.
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.fit(*args, **kwargs)InversePropensityWeighting.get_ate(i, idata)Recover the data of an experiment along with the prediction and causal impact information.
Abstract method for recovering plot data.
Abstract method for recovering plot data.
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.
This weighting scheme was adapted from Lucy D’Agostino McGowan's blog on Propensity Score Weights referenced in the primary CausalPy explainer notebook
This estimator is discussed in Aronow and Miller as the simplest of base form of inverse propensity weighting schemes
This estimator is discussed in Aronow and Miller's book as being related to the Horvitz Thompson method
InversePropensityWeighting.plot(*args, **kwargs)Plot the model.
InversePropensityWeighting.plot_ate([idata, ...])Plotting function takes a single covariate and shows the differences in the ECDF between the treatment and control groups before and after weighting.
Ask the model to print its coefficients.
perc : percentile in [0-1]!
Attributes
idataReturn the InferenceData object of the model.
supports_bayessupports_olslabels- classmethod __new__(*args, **kwargs)#