competing-risk-sensitivity
Sensitivity analysis for a competing event (e.g. death) alongside a primary time-to-event outcome.
A primary survival analysis that censors at a competing event estimates the cause-specific hazard of the event of interest: the instantaneous risk among subjects who are alive and have not yet had the event. That is a defensible choice, but it answers a different question from the subdistribution hazard (Fine-Gray), which describes the cumulative probability of the event actually being observed in the whole population, including subjects who experience the competing event first. The two can point in different directions for a covariate that raises the risk of both events (e.g. advanced age): the cause-specific hazard can look small because high-risk subjects are removed from the risk set by the competing event, while the cumulative incidence of the event of interest in the full population is substantial.
This package provides:
- A cause-specific descriptive summary (event counts, competing-event counts, censoring, crude rates per 1,000 person-years).
- Aalen-Johansen cumulative incidence functions for the event of interest and the competing event -- the non-parametric analogue of Kaplan-Meier under competing risks -- with a risk table and a plot.
- An export of a design matrix, time, and competing-event status, ready for
a Fine-Gray subdistribution hazard model in R via the
cmprskpackage. (There is no maintained Fine-Gray implementation in Python -- lifelines, scikit-survival and statsmodels all lack one -- so the regression itself is fitted in R.) - A comparison of cause-specific Cox coefficients against Fine-Gray subdistribution coefficients, once the R step has been run, to check whether conclusions change under a subdistribution model.
Event-status convention used throughout: 0 = censored, 1 = event of
interest, 2 = competing event.
Install
pip install competing-risk-sensitivity
Command-line use
competing-risk-sensitivity \
--raw-file data_raw_with_dates.tsv \
--train-file X_train_model.tsv \
--out-dir ./results \
--time-col time \
--status-col CompetingEventStatus \
--id-col PPID \
--event-label "relapse" \
--competing-label "death"
Only --raw-file and --out-dir are required; the Fine-Gray export step is
skipped if --train-file is omitted. Run competing-risk-sensitivity --help
for all options.
Library use
import pandas as pd
from competing_risk_sensitivity import (
cause_specific_summary,
aalen_johansen_cif,
finegray_export,
compare_cause_specific_vs_subdistribution,
)
df = pd.read_csv("data_raw_with_dates.tsv", sep="\t")
cause_specific_summary(df["time"], df["status"], out="summary.txt")
aalen_johansen_cif(df["time"], df["status"], out_prefix="results/aj")
X_train = pd.read_csv("X_train_model.tsv", sep="\t", index_col=0)
finegray_export(X_train, df["time"], df["status"], "results/finegray_input.tsv")
Then in R:
d <- read.delim("results/finegray_input.tsv")
cov <- as.matrix(d[, setdiff(names(d), c("time", "status"))])
fit <- cmprsk::crr(d$time, d$status, cov, failcode = 1, cencode = 0)
summary(fit)
Finally, compare the cause-specific Cox model against the Fine-Gray fit:
compare_cause_specific_vs_subdistribution(
"cox_coefficients.tsv", "finegray_coefficients.tsv", out="comparison.tsv",
)
License
MIT
Release files for competing-risk-sensitivity 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| competing_risk_sensitivity-0.1.0.tar.gz | 9.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| competing_risk_sensitivity-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / competing_risk_sensitivity-0.1.0.tar.gz
| Download URL | competing_risk_sensitivity-0.1.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4926db10bfe2463b0f8afff1dd8984cc9d85d7a0941624ff7f55ee04f312358e
|
|
BLAKE2b-256 checksum How to use checksums |
0b6294430994b77c6aaeae54359f6b6bd2c194fc52a6cb467eb976f6df8aa1c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Release files / competing_risk_sensitivity-0.1.0-py3-none-any.whl
| Download URL | competing_risk_sensitivity-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f71381ed5f4f486603bf4190edf9dd87cbf896749f0df65b3134c7d2e49cce6
|
|
BLAKE2b-256 checksum How to use checksums |
977f03c8bd0da3fe40b9a7a7c0d42dc4d437195bcf233679996050f520f23ba2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|