Skip to main content

GuanRank algorithm in Python

Project description

guanrank

Python implementation of the GuanRank hazard ranking algorithm. Assigns a continuous hazard rank to each subject in a survival dataset — higher rank means higher risk of earlier event. Ranks can be used as regression targets for machine learning models in place of raw, right-censored survival times.

Algorithm

GuanRank (Huang et al., 2017) collapses right-censored survival data into a single scalar hazard per subject:

  1. Kaplan-Meier curve. Estimate the survival function SR(t) from all observed event/censoring times.
  2. Pairwise scoring. For every ordered pair of subjects, assign a score in [0, 1] under six rules. When the event ordering is unambiguous (both observed, or one event clearly precedes the other), the earlier-event subject scores 1 and the other 0. When censoring makes the ordering uncertain, the score is the Kaplan-Meier conditional probability ρ(t₁, t₂) = 1 − SR(t₂)/SR(t₁) that the event fell in the ambiguous interval.
  3. Raw rank. Sum each subject's pairwise scores.
  4. Normalization. Divide every raw rank by the largest raw rank in the training set, so the highest-hazard subject maps to 1.0.

Input / output

  • InputsT: time-to-event or censoring time per subject; E: event indicator (1 = event observed, 0 = right-censored).
  • Output — one normalized hazard rank per subject, in input order. In-sample ranks lie in (0, 1], with the highest-hazard subject at 1.0. Out-of-sample ranks from GuanRank.transform share the training scale and may exceed 1.0 when a held-out subject is riskier than every training subject.

The pairwise rules are documented in guankrank_alg.md.

Citation

Huang et al. (2017). Complete hazard ranking to analyze right-censored data: An ALS survival study. PLOS Comp Bio, 15(1), 41–51. https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005887

Installation

pip install guanrank
# or with uv
uv add guanrank

Usage

Functional API

from guanrank import guanrank

T = [5.0, 3.0, 8.0, 3.0]  # time-to-event or censoring times
E = [1,   1,   0,   0  ]  # 1 = event, 0 = censored

ranks = guanrank(T, E)

Sklearn-style API (train/test split)

from guanrank import GuanRank

gr = GuanRank()
train_ranks = gr.fit_transform(T_train, E_train)
test_ranks = gr.transform(T_test, E_test)

fit stores the training cohort's Kaplan-Meier curve and normalization constant (its maximum raw rank); transform scores new subjects against the training cohort and divides by that same constant, keeping held-out ranks on the training scale.

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

guanrank-0.1.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

guanrank-0.1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file guanrank-0.1.2.tar.gz.

File metadata

  • Download URL: guanrank-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for guanrank-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4e4f98ab992a976b3fc0d7f500ee51c48f44a76758d8a8a41de6e7563459ca20
MD5 55e277f7837a74e362b35c6a7d54ab58
BLAKE2b-256 176d7369f0f4198683a6276143598e366b38a549b60792a7f13bcd7576fdf9ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for guanrank-0.1.2.tar.gz:

Publisher: release.yml on d-laub/guanrank

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file guanrank-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: guanrank-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for guanrank-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9692079fcc69d7c221015a21722f1c196cae03b46a73a3b4d81215722636d8b6
MD5 c4bd9f3fc3635cb9bd7b22a761b0ade0
BLAKE2b-256 0d961604fa7d80e5fb9a60e762c1c8c27822056e9b902610cf65a927d6226845

See more details on using hashes here.

Provenance

The following attestation bundles were made for guanrank-0.1.2-py3-none-any.whl:

Publisher: release.yml on d-laub/guanrank

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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