def test_no_model_error(self, df_c): ipsw = IPSW(df_c, exposure='A', outcome='Y', selection='S', generalize=True) with pytest.raises(ValueError): ipsw.fit()
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)
def test_transport_iptw(self, df_iptw): ipsw = IPSW(df_iptw, exposure='A', outcome='Y', selection='S', generalize=False, weights='iptw') ipsw.regression_models('L + W + W_sq', 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)