Metrics

torch_survival.metrics.concordance_index(estimate: Tensor, event: Tensor, time: Tensor, mode: Literal['risk', 'time'] = 'risk') Tensor

Compute Harrell’s concordance index or c-index.

This essentially computes the ratio of correctly ordered pairs while accounting for censoring. Given estimates \(\eta\), event indicators \(\delta\), and times \(t\) it is described by

\[C = \frac{\sum_{i,j} \mathbb{1}_{\eta_i < \eta_j} \mathbb{1}_{t_i > t_j} \delta_j} {\sum_{i,j} \mathbb{1}_{t_i > t_j} \delta_j}.\]

If your model directly predicts survival time, rather than risk, you need to negate the estimates as this function assumes an inverse relationship between estimates and times, i.e., if one increases the other decreases.

Note

While Harrell’s concordance index is easy to interpret, it is known to be biased in the presence of higher amounts of censoring [1]. An alternative is Uno’s concordance index, as implemented in sksurv.metrics.concordance_index_ipcw.

Parameters:
  • estimate (torch.Tensor, of shape (..., n_samples)) – Risks or times estimated by model

  • event (torch.Tensor, of shape (..., n_samples)) – Event indicator denoting whether time is of observed event or dropout

  • time (torch.Tensor, of shape (..., n_samples)) – Time of either observed event or dropout

  • mode (Literal['risk', 'time']) – Whether the passed estimates are risks or survival times

Returns:

Concordance index score

Return type:

torch.Tensor, of shape (…,)