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:
- Kaplan-Meier curve. Estimate the survival function
SR(t)from all observed event/censoring times. - 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. - Raw rank. Sum each subject's pairwise scores.
- 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
- Inputs —
T: 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 at1.0. Out-of-sample ranks fromGuanRank.transformshare the training scale and may exceed1.0when 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e4f98ab992a976b3fc0d7f500ee51c48f44a76758d8a8a41de6e7563459ca20
|
|
| MD5 |
55e277f7837a74e362b35c6a7d54ab58
|
|
| BLAKE2b-256 |
176d7369f0f4198683a6276143598e366b38a549b60792a7f13bcd7576fdf9ee
|
Provenance
The following attestation bundles were made for guanrank-0.1.2.tar.gz:
Publisher:
release.yml on d-laub/guanrank
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
guanrank-0.1.2.tar.gz -
Subject digest:
4e4f98ab992a976b3fc0d7f500ee51c48f44a76758d8a8a41de6e7563459ca20 - Sigstore transparency entry: 2132729505
- Sigstore integration time:
-
Permalink:
d-laub/guanrank@7433710aaeaa439e5556f4479461707a9eb7463c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/d-laub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7433710aaeaa439e5556f4479461707a9eb7463c -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9692079fcc69d7c221015a21722f1c196cae03b46a73a3b4d81215722636d8b6
|
|
| MD5 |
c4bd9f3fc3635cb9bd7b22a761b0ade0
|
|
| BLAKE2b-256 |
0d961604fa7d80e5fb9a60e762c1c8c27822056e9b902610cf65a927d6226845
|
Provenance
The following attestation bundles were made for guanrank-0.1.2-py3-none-any.whl:
Publisher:
release.yml on d-laub/guanrank
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
guanrank-0.1.2-py3-none-any.whl -
Subject digest:
9692079fcc69d7c221015a21722f1c196cae03b46a73a3b4d81215722636d8b6 - Sigstore transparency entry: 2132729557
- Sigstore integration time:
-
Permalink:
d-laub/guanrank@7433710aaeaa439e5556f4479461707a9eb7463c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/d-laub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7433710aaeaa439e5556f4479461707a9eb7463c -
Trigger Event:
workflow_dispatch
-
Statement type: