def test_survdiff_entry_1(): # entry times = 0 is equivalent to no entry times ti = np.r_[1, 3, 4, 2, 5, 4, 6, 7, 5, 9] st = np.r_[1, 1, 0, 1, 1, 0, 1, 1, 0, 0] gr = np.r_[0, 0, 0, 0, 0, 1, 1, 1, 1, 1] entry = np.r_[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] z1, p1 = survdiff(ti, st, gr, entry=entry) z2, p2 = survdiff(ti, st, gr) assert_allclose(z1, z2) assert_allclose(p1, p2)
def test_survdiff_basic(): # Constants taken from R, code above ti = np.concatenate((ti1, ti2)) st = np.concatenate((st1, st2)) groups = np.ones(len(ti)) groups[0:len(ti1)] = 0 z, p = survdiff(ti, st, groups) assert_allclose(z, 2.14673, atol=1e-4, rtol=1e-4) assert_allclose(p, 0.14287, atol=1e-4, rtol=1e-4)
def test_survdiff_entry_3(): # Tests against Stata: # # stset time, failure(status) entry(entry) # sts test group, logrank ti = np.r_[2, 1, 5, 8, 7, 8, 8, 9, 4, 9] st = np.r_[1, 1, 1, 1, 1, 0, 1, 0, 0, 0] gr = np.r_[0, 0, 0, 0, 0, 1, 1, 1, 1, 1] entry = np.r_[1, 1, 2, 2, 3, 3, 2, 1, 2, 0] # Check with no entry times z, p = survdiff(ti, st, gr) assert_allclose(z, 6.9543024) assert_allclose(p, 0.008361789) # Check with entry times z, p = survdiff(ti, st, gr, entry=entry) assert_allclose(z, 6.75082959) assert_allclose(p, 0.00937041)
def test_survdiff_entry_2(): # Tests against Stata: # # stset time, failure(status) entry(entry) # sts test group, logrank ti = np.r_[5, 3, 4, 2, 5, 4, 6, 7, 5, 9] st = np.r_[1, 1, 0, 1, 1, 0, 1, 1, 0, 0] gr = np.r_[0, 0, 0, 0, 0, 1, 1, 1, 1, 1] entry = np.r_[1, 2, 2, 1, 3, 3, 5, 4, 2, 5] # Check with no entry times z, p = survdiff(ti, st, gr) assert_allclose(z, 6.694424) assert_allclose(p, 0.00967149) # Check with entry times z, p = survdiff(ti, st, gr, entry=entry) assert_allclose(z, 3.0) assert_allclose(p, 0.083264516)
def test_survdiff(): # Results come from R survival and survMisc packages (survMisc is # used for non G-rho family tests but does not seem to support # stratification) full_df = bmt.copy() df = bmt[bmt.Group != "ALL"].copy() # Not stratified stat, p = survdiff(df["T"], df.Status, df.Group) assert_allclose(stat, 13.44556, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="gb") assert_allclose(stat, 15.38787, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="tw") assert_allclose(stat, 14.98382, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="fh", fh_p=0.5) assert_allclose(stat, 14.46866, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="fh", fh_p=1) assert_allclose(stat, 14.84500, atol=1e-4, rtol=1e-4) # Not stratified, >2 groups stat, p = survdiff(full_df["T"], full_df.Status, full_df.Group, weight_type="fh", fh_p=1) assert_allclose(stat, 15.67247, atol=1e-4, rtol=1e-4) # 5 strata strata = np.arange(df.shape[0]) % 5 df["strata"] = strata stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata) assert_allclose(stat, 11.97799, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=0.5) assert_allclose(stat, 12.6257, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=1) assert_allclose(stat, 12.73565, atol=1e-4, rtol=1e-4) # 5 strata, >2 groups full_strata = np.arange(full_df.shape[0]) % 5 full_df["strata"] = full_strata stat, p = survdiff(full_df["T"], full_df.Status, full_df.Group, strata=full_df.strata, weight_type="fh", fh_p=0.5) assert_allclose(stat, 13.56793, atol=1e-4, rtol=1e-4) # 8 strata df["strata"] = np.arange(df.shape[0]) % 8 stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata) assert_allclose(stat, 12.12631, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=0.5) assert_allclose(stat, 12.9633, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=1) assert_allclose(stat, 13.35259, atol=1e-4, rtol=1e-4)
def test_survdiff(): # Results come from R survival and survMisc packages (survMisc is # used for non G-rho family tests but does not seem to support # stratification) df = bmt[bmt.Group != "ALL"].copy() # Not stratified stat, p = survdiff(df["T"], df.Status, df.Group) assert_allclose(stat, 13.44556, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="gb") assert_allclose(stat, 15.38787, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="tw") assert_allclose(stat, 14.98382, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="fh", fh_p=0.5) assert_allclose(stat, 14.46866, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="fh", fh_p=1) assert_allclose(stat, 14.84500, atol=1e-4, rtol=1e-4) # 5 strata strata = np.arange(df.shape[0]) % 5 df["strata"] = strata stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata) assert_allclose(stat, 11.97799, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=0.5) assert_allclose(stat, 12.6257, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=1) assert_allclose(stat, 12.73565, atol=1e-4, rtol=1e-4) # 8 strata df["strata"] = np.arange(df.shape[0]) % 8 stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata) assert_allclose(stat, 12.12631, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=0.5) assert_allclose(stat, 12.9633, atol=1e-4, rtol=1e-4) stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata, weight_type="fh", fh_p=1) assert_allclose(stat, 13.35259, atol=1e-4, rtol=1e-4)