Skip to main content

A Python package for simulating survival data, inspired by the R package genSurv

Project description

gen_surv

Coverage Docs PyPI Tests Python

gen_surv is a Python package for simulating survival data under a variety of models, inspired by the R package genSurv. It supports data generation for:

  • Cox Proportional Hazards Models (CPHM)
  • Continuous-Time Markov Models (CMM)
  • Time-Dependent Covariate Models (TDCM)
  • Time-Homogeneous Hidden Markov Models (THMM)

๐Ÿ“ฆ Installation

poetry install

โœจ Features

  • Consistent interface across models
  • Censoring support (uniform or exponential)
  • Easy integration with pandas and NumPy
  • Suitable for benchmarking survival algorithms and teaching
  • Accelerated Failure Time (Log-Normal) model generator
  • Command-line interface powered by Typer

๐Ÿงช Example

from gen_surv import generate

# CPHM
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covar=2.0)

# AFT Log-Normal
generate(model="aft_ln", n=100, beta=[0.5, -0.3], sigma=1.0, model_cens="exponential", cens_par=3.0)

# CMM
generate(model="cmm", n=100, model_cens="exponential", cens_par=2.0,
         qmat=[[0, 0.1], [0.05, 0]], p0=[1.0, 0.0])

# TDCM
generate(model="tdcm", n=100, dist="weibull", corr=0.5,
         dist_par=[1, 2, 1, 2], model_cens="uniform", cens_par=1.0,
         beta=[0.1, 0.2, 0.3], lam=1.0)

# THMM
generate(model="thmm", n=100, qmat=[[0, 0.2, 0], [0.1, 0, 0.1], [0, 0.3, 0]],
         emission_pars={"mu": [0.0, 1.0, 2.0], "sigma": [0.5, 0.5, 0.5]},
         p0=[1.0, 0.0, 0.0], model_cens="exponential", cens_par=3.0)

โŒจ๏ธ Command-Line Usage

Install the package and use python -m gen_surv to generate datasets without writing Python code:

python -m gen_surv dataset aft_ln --n 100 > data.csv

๐Ÿ”ง API Overview

Function Description
generate() Unified interface that calls any generator
gen_cphm() Cox Proportional Hazards Model
gen_cmm() Continuous-Time Multi-State Markov Model
gen_tdcm() Time-Dependent Covariate Model
gen_thmm() Time-Homogeneous Markov Model
gen_aft_log_normal() Accelerated Failure Time Log-Normal
sample_bivariate_distribution() Sample correlated Weibull or exponential times
runifcens() Generate uniform censoring times
rexpocens() Generate exponential censoring times
genSurvPy/
โ”œโ”€โ”€ gen_surv/             # Pacote principal
โ”‚   โ”œโ”€โ”€ __main__.py       # Interface CLI via python -m
โ”‚   โ”œโ”€โ”€ cphm.py
โ”‚   โ”œโ”€โ”€ cmm.py
โ”‚   โ”œโ”€โ”€ tdcm.py
โ”‚   โ”œโ”€โ”€ thmm.py
โ”‚   โ”œโ”€โ”€ censoring.py
โ”‚   โ”œโ”€โ”€ bivariate.py
โ”‚   โ”œโ”€โ”€ validate.py
โ”‚   โ””โ”€โ”€ interface.py
โ”œโ”€โ”€ tests/                # Testes automatizados
โ”‚   โ”œโ”€โ”€ test_cphm.py
โ”‚   โ”œโ”€โ”€ test_cmm.py
โ”‚   โ”œโ”€โ”€ test_tdcm.py
โ”‚   โ”œโ”€โ”€ test_thmm.py
โ”œโ”€โ”€ examples/             # Exemplos de uso
โ”‚   โ”œโ”€โ”€ run_aft.py
โ”‚   โ”œโ”€โ”€ run_cmm.py
โ”‚   โ”œโ”€โ”€ run_cphm.py
โ”‚   โ”œโ”€โ”€ run_tdcm.py
โ”‚   โ””โ”€โ”€ run_thmm.py
โ”œโ”€โ”€ docs/                 # Documentaรงรฃo Sphinx
โ”‚   โ”œโ”€โ”€ source/
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ scripts/              # Utilidades diversas
โ”‚   โ””โ”€โ”€ check_version_match.py
โ”œโ”€โ”€ tasks.py              # Tarefas automatizadas com Invoke
โ”œโ”€โ”€ TODO.md               # Roadmap de desenvolvimento
โ”œโ”€โ”€ pyproject.toml        # Configurado com Poetry
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ LICENCE
โ””โ”€โ”€ .gitignore

๐Ÿง  License

MIT License. See LICENCE for details.

๐Ÿ”– Release Process

This project uses Git tags to manage releases. A GitHub Actions workflow (version-check.yml) verifies that the version declared in pyproject.toml matches the latest Git tag. If they diverge, the workflow fails and prompts a correction before merging. Run python scripts/check_version_match.py locally before creating a tag to catch issues early.

๐ŸŒŸ Code of Conduct

Please read our Code of Conduct to learn about the expectations for participants in this project.

๐Ÿค Contributing

Please read CONTRIBUTING.md for guidelines on setting up your environment, running tests, and submitting pull requests.

๐Ÿ”ง Development Tasks

Common project commands are defined in tasks.py and can be executed with Invoke:

poetry run inv -l  # list available tasks
poetry run inv test  # run the test suite

๐Ÿ“‘ Citation

If you use gen_surv in your work, please cite it using the metadata in CITATION.cff. Many reference managers can import this file directly.

Author

Diogo Ribeiro โ€” ESMAD - Instituto Politรฉcnico do Porto

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

gen_surv-1.0.8.tar.gz (11.2 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.0.8-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gen_surv-1.0.8.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.9.13 Darwin/24.5.0

File hashes

Hashes for gen_surv-1.0.8.tar.gz
Algorithm Hash digest
SHA256 bd79e82786ec71104803c82a9adb74c1eb6132fc935c3143b2723d98c109025e
MD5 93ac09a6b87b2349ec13242d8f91cb1c
BLAKE2b-256 d4e41c0e73cf44bb397069b6be573a34db455f83a24aad2848f143f9463a2286

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gen_surv-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.9.13 Darwin/24.5.0

File hashes

Hashes for gen_surv-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ee3cb179e47cc4c6fea8bcb08e754e4b0dad65af178e2e796ca3d75bb3144913
MD5 be660c947520744e24f4b94b945432f8
BLAKE2b-256 2616147d040b391d84b3bc4510cf5cd61860f7214d28389008ac66b81661c2c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page