samecode.survival package

Submodules

samecode.survival.plot module

class samecode.survival.plot.KMPlot(data, time, event, label, **kwargs)[source]

Bases: object

compare()[source]
fit(data, time, event, label, **kwargs)[source]
plot(labels=None, **kwargs)[source]

Plot the Kaplan-Meier survival curves.

Parameters:
  • labels (list, optional): Labels to plot. Default is None.

  • display_labels (list, optional): Labels to display. Default is None.

  • ax (matplotlib.axes.Axes, optional): Matplotlib axes object. Default is False.

  • colors (list or str, optional): Colors for each label. Default is determined by sns.color_palette.

  • linestyle (list, optional): Line styles for each label. Default is [‘-‘]*len(plot_labels).

  • xy_font_size (int, optional): Font size for x and y axis labels. Default is 12.

  • label_height_adj (float, optional): Adjustment for space between labels on the y-axis. Default is 0.05.

  • template_color (str, optional): Color for template. Default is ‘black’.

  • comparisons (list, optional): List of comparisons between two curves. Default is [].

  • title_weight (str, optional): Font weight for title. Default is ‘normal’.

  • title_size (int, optional): Font size for title. Default is 14.

  • hr_color (str, optional): Color for hazard ratio layer. Default is determined by self.colors.

  • x_legend (float, optional): X-coordinate for legend. Default is 0.15.

  • y_legend (float, optional): Y-coordinate for legend. Default is 0.95.

  • legend_font_size (int, optional): Font size for legend. Default is 10.

  • show_censor (bool, optional): Whether to show censor. Default is True.

  • ylabel (str, optional): Label for y-axis. Default is ‘Survival Probability’.

  • xlabel (str, optional): Label for x-axis. Default is ‘Timeline’.

  • ci_show (bool, optional): Whether to show confidence interval. Default is False.

  • label_weight (str, optional): Font weight for labels. Default is ‘bold’.

  • x_hr_legend (float, optional): X-coordinate for hazard ratio legend. Default is 0.0.

  • y_hr_legend (float, optional): Y-coordinate for hazard ratio legend. Default is -0.3.

  • hr_font_size (int, optional): Font size for hazard ratio legend. Default is 10.

  • saturation (float, optional): Saturation level for colors. Default is 1.0.

  • linewidth (float, optional): Line width for the curves. Default is 1.5.

  • palette (str, optional): Palette for color selection. Default is ‘Paired’.

  • show_cesor (bool, optional): Whether to show censor. Default is True.

Returns:
  • ax: Matplotlib axes object.

class samecode.survival.plot.PlotSurvival(data, time, censor)[source]

Bases: object

time: censor:

add(ix, name='')[source]
hazard()[source]
plot(ax, ref='', targets=[], colors=[], line_styles='-', table=True, plot=True, legend=True, linewidth=2, legend_font_size=4, legend_weight='bold', labelspacing=0.1, table_font_size=10, label_font_size=10, bbox=[-0.0, -0.38, 1, 0.2], lbox=[0.05, 0.01])[source]
table(axs)[source]
class samecode.survival.plot.PrettyPlotSurvival(data, time, censor)[source]

Bases: object

time: censor:

add(ix, name='')[source]
hazard()[source]
plot(ax, ref='', targets=[], colors=[], line_styles='-', table=False, plot=True, legend=False, linewidth=2, legend_font_size=12, legend_weight='bold', labelspacing=0.1, table_font_size=10, label_font_size=10, bbox=[-0.0, -0.38, 1, 0.2], medians_offset=[0, 0], labels_offset=[0, 0, 0, 0], fill_color='white', fill_alpha=0.1)[source]
table(axs)[source]
samecode.survival.plot.compute_char_positions_ascii(font_size=12)[source]
samecode.survival.plot.cox_functions(data, predictor='label', control_arm_label=None, iteration_column=None, time='time', event='event', **kwargs)[source]
samecode.survival.plot.fix_string(s, v, m)[source]
samecode.survival.plot.forestplot(perf, figsize=(8, 3), ax=[], hr='hr', hi='hr_hi', lo='hr_lo', **kwargs)[source]

Plot a forest plot.

Parameters:
  • perf (DataFrame): Dataframe containing performance data.

  • figsize (tuple, optional): Figure size. Default is (8, 3).

  • ax (matplotlib.axes.Axes, optional): Matplotlib axes object. Default is an empty list [].

  • hr (str, optional): Column name for hazard ratio. Default is ‘hr’.

  • hi (str, optional): Column name for upper confidence interval. Default is ‘hr_hi’.

  • lo (str, optional): Column name for lower confidence interval. Default is ‘hr_lo’.

  • marker (str, optional): Marker style. Default is ‘D’.

  • marker_s (int, optional): Marker size. Default is 80.

  • marker_edgecolor (str, optional): Marker edge color. Default is ‘#000000’.

  • marker_c (str, optional): Marker color. Default is ‘#000000’.

  • label_fontsize (int, optional): Font size for labels. Default is 10.

  • table_fontsize (int, optional): Font size for table. Default is 10.

  • xlabel (str, optional): Label for x-axis. Default is ‘Hazard Ratio’.

  • xlim (list, optional): Limits for x-axis. Default is [0.25, 1.5].

  • variable (str, optional): Column name for variable. Default is ‘cluster’.

  • xticks (list, optional): Tick positions for x-axis. Default is None.

  • xticks_labelsize (int, optional): Font size for x-axis ticks. Default is 10.

  • N1 (str, optional): Name for the first group. Default is ‘N1’.

  • N2 (str, optional): Name for the second group. Default is ‘N2’.

  • sort_by (str, optional): Column name for sorting. Default is False.

  • population (str, optional): Column name for population. Default is None.

  • variables (set, optional): Set of variables. Default is set(perf[variable].values).

  • variable_shapes (dict, optional): Dictionary mapping variables to marker shapes. Default is {variable: marker}.

  • populations (set, optional): Set of populations. Default is set(perf[population].values).

  • population_name (str, optional): Column name for population name. Default is None.

  • population_colors (dict, optional): Dictionary mapping populations to colors. Default is {population: ‘black’}.

  • group (str, optional): Column name for group. Default is None.

  • groups (set, optional): Set of groups. Default is set(perf[group].values) if group else [np.nan].

  • offset (int, optional): Offset value. Default is 1.

  • offset2 (float, optional): Another offset value. Default is 0.2.

  • population_label_fixed_position (float, optional): Fixed position for population label. Default is None.

  • population_label_offset (float, optional): Offset for population label. Default is 0.1.

  • population_label_fontsize (int, optional): Font size for population label. Default is 10.

  • xlabel_offset (float, optional): Offset for x-axis label. Default is xlim[1].

  • ylabel_offset (float, optional): Offset for y-axis label. Default is 0.

  • ylabel_align (str, optional): Alignment for y-axis label. Default is ‘left’.

  • legend (bool, optional): Whether to show legend. Default is False.

  • variable_names (list, optional): List of variable names. Default is variables.

  • legend_xoffset (float, optional): X offset for legend. Default is xlim[1] / 2.

  • legend_yoffset (float, optional): Y offset for legend. Default is 0.

Returns:
  • ax: Matplotlib axes object.

samecode.survival.plot.get_end_position(label, positions)[source]
samecode.survival.plot.kmf_survival_functions(data, predictor='label', iteration_column=None, time='time', event='event')[source]

Retrieve all KM survival functions using input data

samecode.survival.plot.median_plot_survival(kmfs, cox=[], label='', agg='mean', color='#573411', ax=[], linewidth=2, plot_medians=True, linecolor=None, alpha=0.25, label_font_size=12, hr_font_size=10, hr_label_offset=-0.03, median_time_offset=[0, 0], name_offset=[0, 0], median_time_fontsize=20)[source]

Plot survival for multiple iterations of the data. Training / Testing splits.

samecode.survival.plot.set_template(ax, **kwargs)[source]
samecode.survival.plot.simple_survival_plot(data, time, event, label, score, **kwargs)[source]

Module contents

samecode.survival.extract_kmstats(data, features, time, event, labels=[0, 1])[source]

Extract a table with km statistics on a given set of clusters or features present in the data

Args:

data (dataframe): pandas dataframe with the data. features (list): list of features to compute the KM stats. time (str): time column. event (str): event column.