Skip to main content

gen_surv

Coverage Docs PyPI Tests Python

GitHub stars GitHub forks

gen_surv is a Python library for simulating survival data and producing visualizations under a wide range of statistical models. Inspired by the R package genSurv, it offers a unified interface for generating realistic datasets for research, teaching and benchmarking.


Features

  • Cox proportional hazards model (CPHM)
  • Accelerated failure time models (log-normal, log-logistic, Weibull)
  • Continuous-time multi-state Markov model (CMM)
  • Time-dependent covariate model (TDCM)
  • Time-homogeneous Markov model (THMM)
  • Mixture cure and piecewise exponential models
  • Competing risks generators (constant and Weibull hazards)
  • Visualization helpers built on matplotlib and lifelines
  • Scikit-learn compatible data generator
  • Conversion utilities for scikit-survival
  • Command-line interface for dataset creation and visualization

Installation

Requires Python 3.11 or later (tested on 3.11, 3.12 and 3.13).

Install the latest release from PyPI:

pip install gen-surv

gen_surv installs matplotlib and lifelines for visualization. Support for scikit-survival is optional; install it to enable integration with the scikit-survival ecosystem or to run the full test suite:

pip install scikit-survival

To develop locally with all extras:

git clone https://github.com/DiogoRibeiro7/genSurvPy.git
cd genSurvPy
poetry install --with dev

On Debian/Ubuntu you may need build-essential gfortran libopenblas-dev to build scikit-survival.

Development

Before committing changes, install the pre-commit hooks and run the tests:

pre-commit install
pre-commit run --all-files
pytest

Tests that depend on optional packages such as scikit-survival are skipped automatically when those packages are missing.

Usage

Python API

from gen_surv import generate, export_dataset, to_sksurv
from gen_surv.visualization import plot_survival_curve

sim = generate(
    model="cphm",
    n=100,
    beta=0.5,
    covariate_range=2.0,
    model_cens="uniform",
    cens_par=1.0,
)

plot_survival_curve(sim)
export_dataset(sim, "survival_data.rds")

# convert for scikit-survival
sks_dataset = to_sksurv(sim)

See the usage guide for more examples.

Command Line

Generate datasets and plots without writing Python code:

python -m gen_surv dataset cphm --n 1000 -o survival.csv

python -m gen_surv visualize survival.csv --output survival_plot.png

visualize accepts custom column names via --time-col and --status-col and can stratify by group with --group-col.

Supported Models

Model Description
CPHM Cox proportional hazards
AFT Accelerated failure time (log-normal, log-logistic, Weibull)
CMM Continuous-time multi-state Markov
TDCM Time-dependent covariates
THMM Time-homogeneous Markov
Competing Risks Multiple event types with cause-specific hazards
Mixture Cure Models long-term survivors
Piecewise Exponential Flexible baseline hazard via intervals

More details on each algorithm are available in the Algorithms page. For additional background, see the theory guide.

Documentation

Full documentation is hosted on Read the Docs. It includes installation instructions, tutorials, API references and a bibliography.

To build the docs locally:

cd docs
make html

Open build/html/index.html in your browser to view the result.

License

This project is licensed under the MIT License. See LICENSE for details.

Citation

If you use gen_surv in your research, please cite the project using the metadata in CITATION.cff.

Author

Diogo RibeiroESMAD - Instituto Politécnico do Porto

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gen_surv-1.3.0.tar.gz (37.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gen_surv-1.3.0-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file gen_surv-1.3.0.tar.gz.

File metadata

  • Download URL: gen_surv-1.3.0.tar.gz
  • Upload date:
  • Size: 37.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gen_surv-1.3.0.tar.gz
Algorithm Hash digest
SHA256 265112ba09a74ae240e8bed8265f80bc11e7f1006c5e42e99943108fffcf3e0e
MD5 95229a1ab0d2d8cdbaa30af33070c81d
BLAKE2b-256 1d7b89ffc13c60c3fe3aee63636a2a9d117ac1b4dec3aab1402b165c8f9de058

See more details on using hashes here.

Provenance

The following attestation bundles were made for gen_surv-1.3.0.tar.gz:

Publisher: publish.yml on DiogoRibeiro7/genSurvPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gen_surv-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: gen_surv-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gen_surv-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88da8d36258dbdeea86be57e95c4176c81ecb6b08701efe5fc8604eb331f6ac5
MD5 772824c524b4492d5fd04eddfccf6203
BLAKE2b-256 38d9e50a783f5d2671a6b8fa2e9ed6af79793f5016c7193b94282b244f6f6cda

See more details on using hashes here.

Provenance

The following attestation bundles were made for gen_surv-1.3.0-py3-none-any.whl:

Publisher: publish.yml on DiogoRibeiro7/genSurvPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

3.1.2

2 files

3.1.1

2 files

3.1.0

2 files

3.0.0

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

This release

1.3.0 This release

2 files

1.2.0

2 files

1.0.8

2 files

1.0.7

2 files

1.0.5

2 files

1.0.3

2 files

0.7.4

2 files

0.7.2

2 files

0.7.1

2 files

0.6.9

2 files

0.6.7

2 files

0.6.6

2 files

0.6.3

2 files

0.6.1

2 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