njab.plotting.km module

njab.plotting.km module#

njab.plotting.km.compare_km_curves(time: Series, y: Series, pred: Series, ax: Axes | None = None, ylim: tuple[int] = (0, 1), xlim: tuple[int] = (0, 180), xlabel: str | None = None, ylabel: str | None = None, add_risk_counts=False) Axes[source]#

Compare Kaplan-Meier curves for two groups (e.g. based on binary prediction)

Parameters:
  • time (pd.Series) – Time to event variable

  • y (pd.Series) – event variable

  • pred (pd.Series) – mask for two groups, e.g. predictions

  • ax (Axes, optional) – matplotlib Axes object, by default None

  • ylim (tuple[int], optional) – y-axis bounds, by default (0, 1)

  • xlim (tuple[int], optional) – time-axis bounds, by default (0, 730)

  • xlabel (str, optional) – time-axis label, by default None

  • ylabel (str, optional) – y-axis label, by default None

Returns:

Axes object, KaplanMeierFitter for predited as 0, KaplanMeierFitter for predicted as 1

Return type:

Axes, KaplanMeierFitter, KaplanMeierFitter

njab.plotting.km.log_rank_test(time: Series, y: Series, mask: Series) StatisticalResult[source]#

Compare Kaplan-Meier curves for two groups (e.g. based on binary prediction). Given the grouping in the mask, are both KM curves significantly different?

Parameters:
  • time (pd.Series) – Time to event variable

  • y (pd.Series) – event variable

  • mask (pd.Series) – mask for two groups, e.g. predictions

Returns:

object containing results with a wrapper for visualization

Return type:

StatisticalResult