Mercurial > repos > fubar > lifelines_km_cph_tool
comparison lifelines_tool/plotlykm.py @ 2:dd5e65893cb8 draft default tip
add survival and collapsed life table outputs suggested by Wolfgang
author | fubar |
---|---|
date | Thu, 10 Aug 2023 22:52:45 +0000 |
parents | 232b874046a7 |
children |
comparison
equal
deleted
inserted
replaced
1:232b874046a7 | 2:dd5e65893cb8 |
---|---|
96 kmf.fit(df[args.time], df[args.status]) | 96 kmf.fit(df[args.time], df[args.status]) |
97 kmf.plot_survival_function(ax=ax) | 97 kmf.plot_survival_function(ax=ax) |
98 ax.set_title(args.title) | 98 ax.set_title(args.title) |
99 fig.savefig(os.path.join(args.image_dir,'KM_%s.png' % args.title)) | 99 fig.savefig(os.path.join(args.image_dir,'KM_%s.png' % args.title)) |
100 print('#### No grouping variable, so no log rank or other Kaplan-Meier statistical output is available') | 100 print('#### No grouping variable, so no log rank or other Kaplan-Meier statistical output is available') |
101 survdf = lifelines.utils.survival_table_from_events(df[args.time], df[args.status]) | |
102 lifedf = lifelines.utils.survival_table_from_events(df[args.time], df[args.status], collapse=True) | |
103 print("Survival table using time %s and event %s" % (args.time, args.status)) | |
104 with pd.option_context('display.max_rows', None, | |
105 'display.max_columns', None, | |
106 'display.precision', 3, | |
107 ): | |
108 print(survdf) | |
109 print("Life table using time %s and event %s" % (args.time, args.status)) | |
110 with pd.option_context('display.max_rows', None, | |
111 'display.max_columns', None, | |
112 'display.precision', 3, | |
113 ): | |
114 print(lifedf) | |
115 outpath = os.path.join(args.image_dir,'survival_table.tabular') | |
116 survdf.to_csv(outpath, sep='\t') | |
117 outpath = os.path.join(args.image_dir,'life_table.tabular') | |
118 lifedf.to_csv(outpath, sep='\t') | |
101 if len(args.cphcols) > 0: | 119 if len(args.cphcols) > 0: |
102 fig, ax = plt.subplots() | 120 fig, ax = plt.subplots() |
103 ax.set_title('Cox-PH model: %s' % args.title) | 121 ax.set_title('Cox-PH model: %s' % args.title) |
104 cphcols = args.cphcols.strip().split(',') | 122 cphcols = args.cphcols.strip().split(',') |
105 cphcols = [x.strip() for x in cphcols] | 123 cphcols = [x.strip() for x in cphcols] |