Skip to main content

survRM2py

PyPI version License: GPL v3

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.

Metadata

Release files for survrm2py 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for survrm2py 0.1.5
File Size Uploaded
survrm2py-0.1.5.tar.gz 97.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for survrm2py 0.1.5
File Interpreter ABI Platform
survrm2py-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 118.7 kB

Release files / survrm2py-0.1.5.tar.gz

Download URL survrm2py-0.1.5.tar.gz
Size 97.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f1962aa9d9b51396d630c004e25698cef71240fcb3722ab8fd6b49ac5aeb00d9
BLAKE2b-256 checksum
How to use checksums
ede0d5ffc492c33ceba04ae38c77a0543ba877fc08b9fbac6ec9d19c3651eb2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 22, 2026.

Transparency log

Release files / survrm2py-0.1.5-py3-none-any.whl

Download URL survrm2py-0.1.5-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de67f1168572b6bfce71773899dac3779f0a96135662b27ad845f9888722e545
BLAKE2b-256 checksum
How to use checksums
c29f337198c5455bab680ec1e2d483fd97a576162d99513a99356dc7a8184128
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page