def test_stabilize_error(self, df_c): ipsw = IPSW(df_c, exposure='A', outcome='Y', selection='S') with pytest.raises(ValueError): ipsw.sampling_model('L + W_sq', model_numerator='W', stabilized=False, print_results=False)
def test_transport_stabilized(self, df_r): ipsw = IPSW(df_r, exposure='A', outcome='Y', selection='S', generalize=False) ipsw.sampling_model('L + W_sq', print_results=False) ipsw.fit() npt.assert_allclose(ipsw.risk_difference, 0.034896, atol=1e-5) npt.assert_allclose(ipsw.risk_ratio, 1.097139, atol=1e-4)
def test_transport_iptw(self, df_c): ipsw = IPSW(df_c, exposure='A', outcome='Y', selection='S', generalize=False) ipsw.sampling_model('L + W + W_sq', print_results=False) ipsw.treatment_model('L', print_results=False) ipsw.fit() npt.assert_allclose(ipsw.risk_difference, 0.047296, atol=1e-5) npt.assert_allclose(ipsw.risk_ratio, 1.1372, atol=1e-4)
def test_generalize_weight(self, df_c): ipsw = IPSW(df_c, exposure='A', outcome='Y', selection='S', generalize=True, weights='weight') ipsw.sampling_model('L + W + W_sq', print_results=False) ipsw.treatment_model('L', print_results=False) ipsw.fit() npt.assert_allclose(ipsw.risk_difference, 0.055034, atol=1e-5) npt.assert_allclose(ipsw.risk_ratio, 1.167213, atol=1e-4)
def test_generalize_stabilized(self, df_r): ipsw = IPSW(df_r, exposure='A', outcome='Y', selection='S') ipsw.sampling_model('L + W_sq', stabilized=True, print_results=False) ipsw.fit() npt.assert_allclose(ipsw.risk_difference, 0.046809, atol=1e-5) npt.assert_allclose(ipsw.risk_ratio, 1.13905, atol=1e-4)