Skip to main content

Concordance index (C-index) between two right-censored survival series.

Project description

symmetric-concordance

Harrell's concordance index (C-index), extended to right-censored predictions.

The concordance index measures how well a model ranks right-censored survival outcomes: like AUROC, it is a pairwise ranking score (0.5 is chance, 1 is perfect ordering) restricted to the pairs whose ordering is actually known. lifelines' concordance_index computes Harrell's version, but only the outcome may be censored; the prediction is treated as a fully observed number.

When the prediction is itself a right-censored time (say an inferred time-to-event that for some subjects is only a lower bound), the natural extension applies the same comparability rule on both sides: a pair counts only when its order is known in the gold series and in the predicted series (the smaller time is an event). This keeps the same ranking-loss interpretation while letting both series be censored.

Install

pip install symmetric-concordance

Usage

from symmetric_concordance import symmetric_concordance_index

gold_times    = [10, 20, 30, 40, 50]
gold_observed = [1, 1, 1, 1, 1]
pred_times    = [12, 33, 25, 44, 55]
pred_observed = [1, 1, 1, 0, 1]   # the 4th prediction is censored

r = symmetric_concordance_index(gold_times, pred_times, gold_observed, pred_observed)
r.concordance         # 0.888...  (8 of 9 usable pairs agree)
r.n_usable, r.n_pairs # (9, 10)   (one pair isn't orderable on the predicted side)

The two series are aligned by position (row i is the same subject in both). Event flags default to all-observed. The result fields:

  • concordance: comparable-pairs concordance, 0.5 is chance (NaN if no pair is usable)
  • n_usable, n_pairs, frac_usable: pair counts
  • resolution_times: per usable pair, the time it became orderable

For an inverse-probability-of-censoring weighted (IPCW) version, which upweights longer-time pairs to undo the bias toward short survivors, call symmetric_concordance_ipcw. It fits a built-in Kaplan-Meier censoring curve unless you pass your own via censoring= (a fitted lifelines KaplanMeierFitter, any object with .predict, or a callable G(t)):

import numpy as np
from lifelines import KaplanMeierFitter
from symmetric_concordance import symmetric_concordance_ipcw

kmf = KaplanMeierFitter().fit(gold_times, 1 - np.asarray(gold_observed))
r = symmetric_concordance_ipcw(
    gold_times, pred_times, gold_observed, pred_observed, censoring=kmf
)
r.concordance   # IPCW-reweighted

Ties in time aren't orderable (strict <), so tied predictions get no half-credit. IPCW weights are 1 / G(t)**2, with G floored at weight_floor (default 0.05).

Caveats

  • gold_times and pred_times are each used only for within-series ordering, so they need not share a scale, just orient both so bigger = later event. (IPCW is the exception: its binding time max(gold, pred) needs them on the same time axis.)
  • Pass pred_observed when predictions are censored. It defaults to all-observed, which brings back the bias this metric exists to avoid.
  • Series are aligned by position; align by id yourself first if needed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

symmetric_concordance-0.1.0.tar.gz (141.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

symmetric_concordance-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file symmetric_concordance-0.1.0.tar.gz.

File metadata

  • Download URL: symmetric_concordance-0.1.0.tar.gz
  • Upload date:
  • Size: 141.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for symmetric_concordance-0.1.0.tar.gz
Algorithm Hash digest
SHA256 218ac9ec4b954e50418a481301d54dd122146b658c2b8f64cd90dc808532611b
MD5 1290f9069ff053ad4dad1ace30e9d2e2
BLAKE2b-256 89771fde9c057b6ccce86a71a4d58b8577e9970f2819b1486be3cea45866f3a5

See more details on using hashes here.

File details

Details for the file symmetric_concordance-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: symmetric_concordance-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for symmetric_concordance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6201d6da4d04cc84e27947a52655c786cfa16f2d3647122d580b52e4c53bdb5f
MD5 bafaba927f595df91035f9dab59d3102
BLAKE2b-256 4c871a57fffd6838cc4fee7f762994552a1f7e2f4545391432d10e42f35479e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page