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 hidden 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 hidden 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.2.0.tar.gz (36.4 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.2.0-py3-none-any.whl (45.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gen_surv-1.2.0.tar.gz
  • Upload date:
  • Size: 36.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 e7292f64e8351b12baf39ce7647dc303035d713d66247d9d516731c9e8c0d7ff
MD5 d701a9bfdadc6855e27842ee965b03cb
BLAKE2b-256 818e2bc42fcfdfe4e646df830a4fedcf790e59cc940c02b1614dbf6d0aa504ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for gen_surv-1.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: gen_surv-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 45.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b228f2784f8d7c2275debe50e5d59beaf9e4287f08fda5c690386bc7b5defa3
MD5 229aaa6a5b4a837abd7c08b023caa40c
BLAKE2b-256 342e0030543aadf2bf15114850e36a8754693b80cde7f748439121245aeee89c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gen_surv-1.2.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

1.3.0

2 files

This release

1.2.0 This release

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