gen_surv
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 Ribeiro — ESMAD - Instituto Politécnico do Porto
- ORCID: https://orcid.org/0009-0001-2022-7072
- Professional email: dfr@esmad.ipp.pt
- Personal email: diogo.debastos.ribeiro@gmail.com
- GitHub: @DiogoRibeiro7
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7292f64e8351b12baf39ce7647dc303035d713d66247d9d516731c9e8c0d7ff
|
|
| MD5 |
d701a9bfdadc6855e27842ee965b03cb
|
|
| BLAKE2b-256 |
818e2bc42fcfdfe4e646df830a4fedcf790e59cc940c02b1614dbf6d0aa504ab
|
Provenance
The following attestation bundles were made for gen_surv-1.2.0.tar.gz:
Publisher:
publish.yml on DiogoRibeiro7/genSurvPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gen_surv-1.2.0.tar.gz -
Subject digest:
e7292f64e8351b12baf39ce7647dc303035d713d66247d9d516731c9e8c0d7ff - Sigstore transparency entry: 2406852936
- Sigstore integration time:
-
Permalink:
DiogoRibeiro7/genSurvPy@6e0c1484b6b02341a46ebe002ef5c0b54d54f610 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DiogoRibeiro7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6e0c1484b6b02341a46ebe002ef5c0b54d54f610 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b228f2784f8d7c2275debe50e5d59beaf9e4287f08fda5c690386bc7b5defa3
|
|
| MD5 |
229aaa6a5b4a837abd7c08b023caa40c
|
|
| BLAKE2b-256 |
342e0030543aadf2bf15114850e36a8754693b80cde7f748439121245aeee89c
|
Provenance
The following attestation bundles were made for gen_surv-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on DiogoRibeiro7/genSurvPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gen_surv-1.2.0-py3-none-any.whl -
Subject digest:
4b228f2784f8d7c2275debe50e5d59beaf9e4287f08fda5c690386bc7b5defa3 - Sigstore transparency entry: 2406853077
- Sigstore integration time:
-
Permalink:
DiogoRibeiro7/genSurvPy@6e0c1484b6b02341a46ebe002ef5c0b54d54f610 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DiogoRibeiro7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6e0c1484b6b02341a46ebe002ef5c0b54d54f610 -
Trigger Event:
workflow_dispatch
-
Statement type: