Skip to content

comprisk

PyPI version DOI

A Python toolkit for competing risks. It ships a scalable, scikit-learn-compatible competing-risks random survival forest plus the classical regression / non-parametric methods clinical researchers actually need — so competing-risks analysis no longer forces a Python → R workflow split.

Status: alpha

API and internals may change before v1.0. Renamed from crforest in 0.3.1.

Install

pip install comprisk

30-second example

import numpy as np
from comprisk import CompetingRiskForest

rng = np.random.default_rng(42)
n = 1000
X = rng.normal(size=(n, 6))
lp = X[:, 0] + 0.5 * X[:, 1]
t1 = rng.exponential(np.exp(-lp))      # cause 1 (event of interest)
t2 = rng.exponential(2.0, size=n)      # cause 2 (competing)
tc = rng.exponential(4.0, size=n)      # censoring
time = np.minimum.reduce([t1, t2, tc])
event = np.where((t1 <= t2) & (t1 <= tc), 1, np.where(t2 <= tc, 2, 0))  # 0 = censored

forest = CompetingRiskForest(n_estimators=300, random_state=42).fit(X, time, event)
cif = forest.predict_cif(X)                    # (n, n_causes, n_times) Aalen-Johansen CIF
print("OOB C-index, cause 1:", forest.oob_score(cause=1))

What's included

Tool Estimates Validated against
CompetingRiskForest cause-specific CIF, CHF, VIMP, SHAP randomForestSRC
FineGrayRegression subdistribution-hazard ratios cmprsk::crr()
PenalizedFineGrayRegression LASSO/MCP/SCAD Fine-Gray crrp::crrp()
CauseSpecificCox cause-specific hazard ratios survival::coxph()
CumulativeIncidence non-parametric Aalen-Johansen CIF cmprsk::cuminc()
gray_test K-sample test for equal CIFs cmprsk::cuminc()$Tests

Where to next