Python translation of survRM2 for Restricted Mean Survival Time (RMST) analysis
Project description
survRM2py
survRM2py is a Python reimplementation of the popular R package survRM2 for Restricted Mean Survival Time (RMST) analysis. It is designed to achieve absolute mathematical parity with the R reference implementation.
RMST is a robust alternative to the hazard ratio for comparing survival curves, representing the average survival time up to a pre-specified time point (tau).
Installation
Standard Python Environment
You can install the package directly from PyPI:
pip install survrm2py
Quick Start Example
import numpy as np
import pandas as pd
from survrm2py import rmst
# 1. Create mock survival data
np.random.seed(42)
n = 200
data = pd.DataFrame({
"time": np.random.exponential(scale=10, size=n),
"event": np.random.binomial(n=1, p=0.7, size=n),
"arm": np.random.binomial(n=1, p=0.5, size=n),
"age": np.random.normal(loc=60, scale=10, size=n)
})
# 2. Run unadjusted and covariate-adjusted RMST at tau = 8.0
results = rmst(
df=data,
time_col="time",
event_col="event",
arm_col="arm",
tau=8.0,
formula="age", # the formula api instead of covariates list used in the original R package for flexibility
method="ipcw_rmst2"
)
# 3. Print unadjusted differences
print(f"RMST Arm 1: {results['rmst_arm1']:.4f}")
print(f"RMST Arm 0: {results['rmst_arm0']:.4f}")
print(f"Unadjusted Diff: {results['rmst_diff_unadjusted']:.4f} (p={results['p_unadjusted']:.4f})")
# 4. View adjusted covariate summary table
print("\nAdjusted IPCW Regression Summary:")
print(results["adjusted_summary"])
Developer Guide (Pixi)
This package uses a unified pyproject.toml with tool.pixi environment manager.
Prerequisites
Make sure you have Pixi installed:
curl -fsSL https://pixi.sh/install.sh | bash
Running Tests
The test environment automatically sets up Python, R, and installs the reference survRM2 package from CRAN.
pixi run -e test test
Building Package Distribution Files
To build the distribution packages (.whl and .tar.gz) locally in a clean sandboxed environment:
pixi run -e test build
Built files will be generated under the dist/ directory.
License
This package is licensed under the GNU General Public License v3 or later (GPLv3+), which maintains consistency with CRAN's survRM2 licensing.
References
Uno H, Claggett B, Tian L, Inoue E, Gallo P, Miyata T, Schrag D, Takeuchi M, Uyama Y, Zhao L, Skali H, Solomon S, Jacobus S, HughesM, Packer M, Wei LJ. Moving beyond the hazard ratio in quantifying the between-group difference in survival analysis. Journal of clinical Oncology 2014, 32, 2380-2385. doi:10.1200/JCO.2014.55.2208.
Tian L, Zhao L, Wei LJ. Predicting the restricted mean event time with the subject's baseline covariates in survival analysis. Biostatistics 2014, 15, 222-233. doi:10.1093/biostatistics/kxt050.
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
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 survrm2py-0.1.2.tar.gz.
File metadata
- Download URL: survrm2py-0.1.2.tar.gz
- Upload date:
- Size: 88.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 |
6018f6a8d5fd9ae15c5b7a931faa5bfb85adb269a2d367c4787f8ed8eafa68f5
|
|
| MD5 |
f614dd62dbe713a07a47cd08e712f531
|
|
| BLAKE2b-256 |
33be8f7f108b82baf6d9e4259b878ce410a19b6d3edd291619db00ae3a7bf359
|
Provenance
The following attestation bundles were made for survrm2py-0.1.2.tar.gz:
Publisher:
publish.yml on j-bac/survRM2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
survrm2py-0.1.2.tar.gz -
Subject digest:
6018f6a8d5fd9ae15c5b7a931faa5bfb85adb269a2d367c4787f8ed8eafa68f5 - Sigstore transparency entry: 1591919888
- Sigstore integration time:
-
Permalink:
j-bac/survRM2py@6f12a982c0a71dbaf628b74f3f699027a7d7b6c6 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/j-bac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6f12a982c0a71dbaf628b74f3f699027a7d7b6c6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file survrm2py-0.1.2-py3-none-any.whl.
File metadata
- Download URL: survrm2py-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.4 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 |
eb63c35513ac8c3a93b44ac596cb42a4bc07066a33277c670e0dc06af8a503b2
|
|
| MD5 |
7a1e437e5ab2ae17f17c793a2e2e61fd
|
|
| BLAKE2b-256 |
a4892721ca5348dd58a0f2d7a2b2fc71a9f94af5ea9ab55ba7d567295f328b0d
|
Provenance
The following attestation bundles were made for survrm2py-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on j-bac/survRM2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
survrm2py-0.1.2-py3-none-any.whl -
Subject digest:
eb63c35513ac8c3a93b44ac596cb42a4bc07066a33277c670e0dc06af8a503b2 - Sigstore transparency entry: 1591919962
- Sigstore integration time:
-
Permalink:
j-bac/survRM2py@6f12a982c0a71dbaf628b74f3f699027a7d7b6c6 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/j-bac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6f12a982c0a71dbaf628b74f3f699027a7d7b6c6 -
Trigger Event:
release
-
Statement type: