def draw_survival_curve(feature, surv, q=.25, std=None, **args): feature = process_feature(feature, q, std) fmla = robjects.Formula('Surv(days, event) ~ feature') m = get_cox_ph(surv, feature) r_data = m.rx2('call')[2] # s = survival.survdiff(fmla, r_data) # p = str(s).split('\n\n')[-1].strip().split(', ')[-1] draw_survival_curves_mpl(survival.survfit(fmla, r_data), **args)
def plot_me(sub_f, label): if (get_vec_type(sub_f) == 'real') and (len(sub_f.unique()) > 10): sub_f = to_quants(sub_f, q=q, std=std) m = get_cox_ph(surv, sub_f, formula=fmla) r_data = m.rx2('call')[2] p = log_rank(sub_f, surv)['p'] ls = r.c(*colors) r.plot(survival.survfit(fmla, r_data), lty=1, col=ls, lwd=4, cex=1.25, xlab='Years to Event', ylab='Survival'); r.title(label, cex=3.) if ann == 'p': r.text(.2, 0, labels='logrank p = {0:.1e}'.format(p), pos=4) elif ann != None: r.text(0, labels=ann, pos=4)
def plot_me(sub_f, label): if (get_vec_type(sub_f) == 'real') and (len(sub_f.unique()) > 10): sub_f = to_quants(sub_f, q=q, std=std) m = get_cox_ph(surv, sub_f, formula=fmla) r_data = m.rx2('call')[2] p = log_rank(sub_f, surv)['p'] ls = r.c(*colors) r.plot(survival.survfit(fmla, r_data), lty=1, col=ls, lwd=4, cex=1.25, xlab='Years to Event', ylab='Survival') r.title(label, cex=3.) if ann == 'p': r.text(.2, 0, labels='logrank p = {0:.1e}'.format(p), pos=4) elif ann != None: r.text(0, labels=ann, pos=4)