pymc-labs / CausalPy

A Python package for causal inference in quasi-experimental settings
https://causalpy.readthedocs.io
Apache License 2.0
832 stars 53 forks source link

Add propensity weighting schemes and covariate balance plot functionality #311

Closed NathanielF closed 2 months ago

NathanielF commented 3 months ago

In relation to this issue: https://github.com/pymc-labs/CausalPy/issues/303

I'm opening the PR which includes functionality for fitting a propensity score model and analysing the experimental outcomes under different re-weighting schemes.

I've added the relevant classes to and models. I've also demonstrated their use an example notebook with a parameter recovery exercise and an application to real data.

I've added two plotting functions to experiment class to both analyse covariate balance and plot the overlap of the propensity scores and the uncertainty in the estimation of causal effects.

drbenvincent commented 2 months ago

Can you also please update from main? Might help fix some of the failing tests.

NathanielF commented 2 months ago

Can you run make uml to update the UML diagrams? Can we add a docstring to plot_balance_ecdf Maybe add an assert for perc is 0-1 in the InversePropensityWeighting.weighted_percentile method Can you also please update from main? Might help fix some of the failing tests.

Addressed these. Not sure why the doctests are systematically failing. Every one seems to pass for me locally except for one print coefficents:

image

But oddly i haven't touched that method

drbenvincent commented 2 months ago

Addressed these. Not sure why the doctests are systematically failing. Every one seems to pass for me locally except for one print coefficents

So I was getting all tests passing locally, but 12 failing remotely. But after rebuilding the environment I replicated the 12 failing tests. We've got an issue for it https://github.com/pymc-labs/CausalPy/issues/323

NathanielF commented 2 months ago

Will merge from main this evening

drbenvincent commented 2 months ago

2 failing tests. These are the new ones that you've just introduced @NathanielF. This is fixable by adding <BLANKLINE> into the docstrings in the same way that I did in #330. That should hopefully fix everything.