sksurv.compare.compare_survival#

sksurv.compare.compare_survival(y, group_indicator, return_stats=False)[source]#

Compare survival functions of two or more groups using the log-rank test.

The log-rank test is a non-parametric hypothesis test for comparing the survival functions of two or more independent groups. The null hypothesis is that the survival functions of the groups are identical. The alternative hypothesis is that at least one survival function differs from the others.

The test statistic is approximately chi-squared distributed with \(K-1\) degrees of freedom, where \(K\) is the number of groups.

See [1] for more details.

Parameters:
  • y (structured array, shape = (n_samples,)) – A structured array with two fields. The first field is a boolean where True indicates an event and False indicates right-censoring. The second field is a float with the time of event or time of censoring.

  • group_indicator (array-like, shape = (n_samples,)) – Group membership of each sample.

  • return_stats (bool, optional, default: False) – Whether to return a data frame with statistics for each group and the covariance matrix of the test statistic.

Returns:

  • chisq (float) – The test statistic.

  • pvalue (float) – The two-sided p-value for the test.

  • stats (pandas.DataFrame, optional) – A DataFrame with summary statistics for each group. This includes the number of samples, observed number of events, expected number of events, and the test statistic. Only returned if return_stats is True.

  • covariance (ndarray, shape=(n_groups, n_groups), optional) – The covariance matrix of the test statistic. Only returned if return_stats is True.

References