How to use the causality.estimation.parametric.InverseProbabilityWeightedLS function in causality

To help you get started, we’ve selected a few causality examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akelleh / causality / tests / unit / parametric.py View on Github external
def test_estimators(self):
        N = 2000
        z = np.random.normal(size=N)
        d = np.random.binomial(1, p=1. / (1. + np.exp(-z)))
        y0 = np.random.normal(size=N)
        y1 = y0 + 2. * (1 + z)
        y = (d == 1) * y1 + (d == 0) * y0
        X = pd.DataFrame({'d': d, 'z': z, 'y': y, 'y0': y0, 'y1': y1})

        assignment = 'd'
        confounder_types = {'z': 'c'}
        outcome = 'y'
        ipw_model = InverseProbabilityWeightedLS()
        atc_lower, atc_exp, atc_upper = ipw_model.estimate_ATC(X,
                                                               assignment,
                                                               outcome,
                                                               confounder_types,
                                                               propensity_score_name='propensity score')
        assert 0.9 * atc_lower <= (X[X['d'] == 0]['y1'] - X[X['d'] == 0]['y0']).mean() <= 1.1 * atc_upper

        att_lower, att_exp, att_upper = ipw_model.estimate_ATT(X,
                                                               assignment,
                                                               outcome,
                                                               confounder_types,
                                                               propensity_score_name='propensity score')
        assert 0.9 * att_lower <= (X[X['d'] == 1]['y1'] - X[X['d'] == 1]['y0']).mean() <= 1.1 * att_upper


        ate_lower, ate_exp, ate_upper = ipw_model.estimate_ATE(X,