예제 #1
0
 def test_match_sas_ci(self, data_set):
     sas_ci = -0.195996398, 0.195996398
     rd = RiskDifference()
     rd.fit(data_set, exposure='exp', outcome='dis')
     df = rd.results
     npt.assert_allclose(df.loc[df.index == '1'][['RD_LCL', 'RD_UCL']],
                         [sas_ci])
예제 #2
0
 def test_match_sas_sampledata(self):
     sas_rr = -0.045129870
     sas_se = 0.042375793
     sas_ci = -0.128184899, 0.037925158
     df = ze.load_sample_data(False)
     rd = RiskDifference()
     rd.fit(df, exposure='art', outcome='dead')
     npt.assert_allclose(rd.risk_difference[1], sas_rr)
     rf = rd.results
     npt.assert_allclose(rf.loc[rf.index == '1'][['RD_LCL', 'RD_UCL']], [sas_ci])
     npt.assert_allclose(rf.loc[rf.index == '1'][['SD(RD)']], sas_se)
예제 #3
0
    def test_match_inverse_of_risk_difference(self):
        df = ze.load_sample_data(False)

        rd = RiskDifference()
        rd.fit(df, exposure='art', outcome='dead')

        nnt = NNT()
        nnt.fit(df, exposure='art', outcome='dead')

        npt.assert_allclose(nnt.number_needed_to_treat[1], 1/rd.risk_difference[1])
        rf = rd.results
        nf = nnt.results
        npt.assert_allclose(nf.loc[nf.index == '1'][['NNT_LCL', 'NNT_UCL']],
                            1 / rf.loc[rf.index == '1'][['RD_LCL', 'RD_UCL']])
        npt.assert_allclose(nf.loc[nf.index == '1'][['SD(RD)']], rf.loc[rf.index == '1'][['SD(RD)']])
예제 #4
0
def measures_check():
    # 7) Check measures plots
    data_set = load_sample_data(False)
    rr = RiskRatio()
    rr.fit(data_set, exposure='art', outcome='dead')
    rr.plot(fmt='*', ecolor='r', barsabove=True, markersize=25)
    plt.show()
    rd = RiskDifference()
    rd.fit(data_set, exposure='art', outcome='dead')
    rd.plot()
    plt.show()
    ord = OddsRatio()
    ord.fit(data_set, exposure='art', outcome='dead')
    ord.plot()
    plt.show()
    irr = IncidenceRateRatio()
    irr.fit(data_set, exposure='art', outcome='dead', time='t')
    irr.plot()
    plt.show()
    ird = IncidenceRateDifference()
    ird.fit(data_set, exposure='art', outcome='dead', time='t')
    ird.plot()
    plt.show()
예제 #5
0
 def test_multiple_exposures(self, multi_exposures):
     rd = RiskDifference()
     rd.fit(multi_exposures, exposure='exp', outcome='dis')
     assert rd.results.shape[0] == 3
     assert list(rd.results.index) == ['Ref:0', '1', '2']
예제 #6
0
 def test_risk_difference_equal_to_0(self, data_set):
     rd = RiskDifference()
     rd.fit(data_set, exposure='exp', outcome='dis')
     assert rd.risk_difference[1] == 0
예제 #7
0
 def test_frechet_bounds2(self, multi_exposures):
     rd = RiskDifference()
     rd.fit(multi_exposures, exposure='exp', outcome='dis')
     npt.assert_allclose(
         rd.results['UpperBound'][1:] - rd.results['LowerBound'][1:],
         [1.0000, 1.0000])
예제 #8
0
 def test_frechet_bounds(self):
     df = ze.load_sample_data(False)
     rd = RiskDifference()
     rd.fit(df, exposure='art', outcome='dead')
     npt.assert_allclose(
         rd.results['UpperBound'][1] - rd.results['LowerBound'][1], 1.0000)
예제 #9
0
 def test_match_sas_se(self, data_set):
     sas_se = 0.1
     rd = RiskDifference()
     rd.fit(data_set, exposure='exp', outcome='dis')
     df = rd.results
     npt.assert_allclose(df.loc[df.index == '1'][['SD(RD)']], sas_se)
예제 #10
0
#######################################################################################################################
# Binary Outcome
#######################################################################################################################

df = load_sample_data(timevary=False)
df = df.drop(columns=['cd4_wk45'])
df[['cd4_rs1', 'cd4_rs2']] = spline(df, 'cd40', n_knots=3, term=2, restricted=True)
df[['age_rs1', 'age_rs2']] = spline(df, 'age0', n_knots=3, term=2, restricted=True)

#############################
# Naive Risk Difference
from zepid import RiskDifference

rd = RiskDifference()
rd.fit(df, exposure='art', outcome='dead')
rd.summary()

#############################
# G-formula
from zepid.causal.gformula import TimeFixedGFormula

g = TimeFixedGFormula(df, exposure='art', outcome='dead')
g.outcome_model(model='art + male + age0 + age_rs1 + age_rs2 + cd40 + cd4_rs1 + cd4_rs2 + dvl0',
                print_results=False)
# Estimating marginal effect under treat-all plan
g.fit(treatment='all')
r_all = g.marginal_outcome
# Estimating marginal effect under treat-none plan
g.fit(treatment='none')
r_none = g.marginal_outcome