gen-surv 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gen_surv-1.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 [Diogo Ribeiro]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,192 @@
1
+ Metadata-Version: 2.4
2
+ Name: gen_surv
3
+ Version: 1.2.0
4
+ Summary: A Python package for simulating survival data, inspired by the R package genSurv
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: survival-analysis,simulation,cox-model,markov-model,time-dependent,statistics
8
+ Author: Diogo Ribeiro
9
+ Author-email: diogo.debastos.ribeiro@gmail.com
10
+ Requires-Python: >=3.11,<3.14
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Healthcare Industry
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
20
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
21
+ Requires-Dist: click (>=8.3.0,<9.0.0)
22
+ Requires-Dist: lifelines (>=0.30.3,<0.31.0)
23
+ Requires-Dist: matplotlib (>=3.10.7,<4.0.0)
24
+ Requires-Dist: numpy (>=2.3.3,<3.0.0)
25
+ Requires-Dist: pandas (>=2.3.3,<3.0.0)
26
+ Requires-Dist: pyarrow (>=21.0.0,<22.0.0)
27
+ Requires-Dist: pyreadr (>=0.5.3,<0.6.0)
28
+ Requires-Dist: typer (>=0.19.2,<0.20.0)
29
+ Project-URL: Documentation, https://gensurvpy.readthedocs.io/en/latest/
30
+ Project-URL: Homepage, https://github.com/DiogoRibeiro7/genSurvPy
31
+ Project-URL: Repository, https://github.com/DiogoRibeiro7/genSurvPy
32
+ Description-Content-Type: text/markdown
33
+
34
+ # gen_surv
35
+
36
+ [![Coverage][cov-badge]][cov-link]
37
+ [![Docs][docs-badge]][docs-link]
38
+ [![PyPI][pypi-badge]][pypi-link]
39
+ [![Tests][ci-badge]][ci-link]
40
+ [![Python][py-badge]][pypi-link]
41
+
42
+ [cov-badge]: https://codecov.io/gh/DiogoRibeiro7/genSurvPy/branch/main/graph/badge.svg
43
+ [cov-link]: https://app.codecov.io/gh/DiogoRibeiro7/genSurvPy
44
+ [docs-badge]: https://readthedocs.org/projects/gensurvpy/badge/?version=latest
45
+ [docs-link]: https://gensurvpy.readthedocs.io/en/latest/
46
+ [pypi-badge]: https://img.shields.io/pypi/v/gen_surv
47
+ [pypi-link]: https://pypi.org/project/gen-surv/
48
+ [ci-badge]: https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/ci.yml/badge.svg
49
+ [ci-link]: https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/ci.yml
50
+ [py-badge]: https://img.shields.io/pypi/pyversions/gen_surv
51
+ [![GitHub stars](https://img.shields.io/github/stars/diogoribeiro7/genSurvPy.svg?style=social)](https://github.com/diogoribeiro7/genSurvPy/stargazers)
52
+ [![GitHub forks](https://img.shields.io/github/forks/diogoribeiro7/genSurvPy.svg?style=social)](https://github.com/diogoribeiro7/genSurvPy/network/members)
53
+
54
+ **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](https://cran.r-project.org/package=genSurv), it offers a unified interface for generating realistic datasets for research, teaching and benchmarking.
55
+
56
+ ---
57
+
58
+ ## Features
59
+
60
+ - Cox proportional hazards model (CPHM)
61
+ - Accelerated failure time models (log-normal, log-logistic, Weibull)
62
+ - Continuous-time multi-state Markov model (CMM)
63
+ - Time-dependent covariate model (TDCM)
64
+ - Time-homogeneous hidden Markov model (THMM)
65
+ - Mixture cure and piecewise exponential models
66
+ - Competing risks generators (constant and Weibull hazards)
67
+ - Visualization helpers built on matplotlib and lifelines
68
+ - Scikit-learn compatible data generator
69
+ - Conversion utilities for scikit-survival
70
+ - Command-line interface for dataset creation and visualization
71
+
72
+ ## Installation
73
+
74
+ Requires Python 3.11 or later (tested on 3.11, 3.12 and 3.13).
75
+
76
+ Install the latest release from PyPI:
77
+
78
+ ```bash
79
+ pip install gen-surv
80
+ ```
81
+
82
+ `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:
83
+
84
+ ```bash
85
+ pip install scikit-survival
86
+ ```
87
+
88
+ To develop locally with all extras:
89
+
90
+ ```bash
91
+ git clone https://github.com/DiogoRibeiro7/genSurvPy.git
92
+ cd genSurvPy
93
+ poetry install --with dev
94
+ ```
95
+
96
+ On Debian/Ubuntu you may need `build-essential gfortran libopenblas-dev` to build scikit-survival.
97
+
98
+ ## Development
99
+
100
+ Before committing changes, install the pre-commit hooks and run the tests:
101
+
102
+ ```bash
103
+ pre-commit install
104
+ pre-commit run --all-files
105
+ pytest
106
+ ```
107
+
108
+ Tests that depend on optional packages such as scikit-survival are skipped automatically when those packages are missing.
109
+
110
+ ## Usage
111
+
112
+ ### Python API
113
+
114
+ ```python
115
+ from gen_surv import generate, export_dataset, to_sksurv
116
+ from gen_surv.visualization import plot_survival_curve
117
+
118
+ sim = generate(
119
+ model="cphm",
120
+ n=100,
121
+ beta=0.5,
122
+ covariate_range=2.0,
123
+ model_cens="uniform",
124
+ cens_par=1.0,
125
+ )
126
+
127
+ plot_survival_curve(sim)
128
+ export_dataset(sim, "survival_data.rds")
129
+
130
+ # convert for scikit-survival
131
+ sks_dataset = to_sksurv(sim)
132
+ ```
133
+
134
+ See the [usage guide](https://gensurvpy.readthedocs.io/en/latest/getting_started.html) for more examples.
135
+
136
+ ### Command Line
137
+
138
+ Generate datasets and plots without writing Python code:
139
+
140
+ ```bash
141
+ python -m gen_surv dataset cphm --n 1000 -o survival.csv
142
+
143
+ python -m gen_surv visualize survival.csv --output survival_plot.png
144
+ ```
145
+
146
+ `visualize` accepts custom column names via `--time-col` and `--status-col` and can stratify by group with `--group-col`.
147
+
148
+ ## Supported Models
149
+
150
+ | Model | Description |
151
+ |-------|-------------|
152
+ | **CPHM** | Cox proportional hazards |
153
+ | **AFT** | Accelerated failure time (log-normal, log-logistic, Weibull) |
154
+ | **CMM** | Continuous-time multi-state Markov |
155
+ | **TDCM** | Time-dependent covariates |
156
+ | **THMM** | Time-homogeneous hidden Markov |
157
+ | **Competing Risks** | Multiple event types with cause-specific hazards |
158
+ | **Mixture Cure** | Models long-term survivors |
159
+ | **Piecewise Exponential** | Flexible baseline hazard via intervals |
160
+
161
+ More details on each algorithm are available in the [Algorithms](https://gensurvpy.readthedocs.io/en/latest/algorithms.html) page. For additional background, see the [theory guide](https://gensurvpy.readthedocs.io/en/latest/theory.html).
162
+
163
+ ## Documentation
164
+
165
+ Full documentation is hosted on [Read the Docs](https://gensurvpy.readthedocs.io/en/latest/). It includes installation instructions, tutorials, API references and a bibliography.
166
+
167
+ To build the docs locally:
168
+
169
+ ```bash
170
+ cd docs
171
+ make html
172
+ ```
173
+
174
+ Open `build/html/index.html` in your browser to view the result.
175
+
176
+ ## License
177
+
178
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
179
+
180
+ ## Citation
181
+
182
+ If you use **gen_surv** in your research, please cite the project using the metadata in [CITATION.cff](CITATION.cff).
183
+
184
+ ## Author
185
+
186
+ **Diogo Ribeiro** — [ESMAD - Instituto Politécnico do Porto](https://esmad.ipp.pt)
187
+
188
+ - ORCID: <https://orcid.org/0009-0001-2022-7072>
189
+ - Professional email: <dfr@esmad.ipp.pt>
190
+ - Personal email: <diogo.debastos.ribeiro@gmail.com>
191
+ - GitHub: [@DiogoRibeiro7](https://github.com/DiogoRibeiro7)
192
+
@@ -0,0 +1,158 @@
1
+ # gen_surv
2
+
3
+ [![Coverage][cov-badge]][cov-link]
4
+ [![Docs][docs-badge]][docs-link]
5
+ [![PyPI][pypi-badge]][pypi-link]
6
+ [![Tests][ci-badge]][ci-link]
7
+ [![Python][py-badge]][pypi-link]
8
+
9
+ [cov-badge]: https://codecov.io/gh/DiogoRibeiro7/genSurvPy/branch/main/graph/badge.svg
10
+ [cov-link]: https://app.codecov.io/gh/DiogoRibeiro7/genSurvPy
11
+ [docs-badge]: https://readthedocs.org/projects/gensurvpy/badge/?version=latest
12
+ [docs-link]: https://gensurvpy.readthedocs.io/en/latest/
13
+ [pypi-badge]: https://img.shields.io/pypi/v/gen_surv
14
+ [pypi-link]: https://pypi.org/project/gen-surv/
15
+ [ci-badge]: https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/ci.yml/badge.svg
16
+ [ci-link]: https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/ci.yml
17
+ [py-badge]: https://img.shields.io/pypi/pyversions/gen_surv
18
+ [![GitHub stars](https://img.shields.io/github/stars/diogoribeiro7/genSurvPy.svg?style=social)](https://github.com/diogoribeiro7/genSurvPy/stargazers)
19
+ [![GitHub forks](https://img.shields.io/github/forks/diogoribeiro7/genSurvPy.svg?style=social)](https://github.com/diogoribeiro7/genSurvPy/network/members)
20
+
21
+ **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](https://cran.r-project.org/package=genSurv), it offers a unified interface for generating realistic datasets for research, teaching and benchmarking.
22
+
23
+ ---
24
+
25
+ ## Features
26
+
27
+ - Cox proportional hazards model (CPHM)
28
+ - Accelerated failure time models (log-normal, log-logistic, Weibull)
29
+ - Continuous-time multi-state Markov model (CMM)
30
+ - Time-dependent covariate model (TDCM)
31
+ - Time-homogeneous hidden Markov model (THMM)
32
+ - Mixture cure and piecewise exponential models
33
+ - Competing risks generators (constant and Weibull hazards)
34
+ - Visualization helpers built on matplotlib and lifelines
35
+ - Scikit-learn compatible data generator
36
+ - Conversion utilities for scikit-survival
37
+ - Command-line interface for dataset creation and visualization
38
+
39
+ ## Installation
40
+
41
+ Requires Python 3.11 or later (tested on 3.11, 3.12 and 3.13).
42
+
43
+ Install the latest release from PyPI:
44
+
45
+ ```bash
46
+ pip install gen-surv
47
+ ```
48
+
49
+ `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:
50
+
51
+ ```bash
52
+ pip install scikit-survival
53
+ ```
54
+
55
+ To develop locally with all extras:
56
+
57
+ ```bash
58
+ git clone https://github.com/DiogoRibeiro7/genSurvPy.git
59
+ cd genSurvPy
60
+ poetry install --with dev
61
+ ```
62
+
63
+ On Debian/Ubuntu you may need `build-essential gfortran libopenblas-dev` to build scikit-survival.
64
+
65
+ ## Development
66
+
67
+ Before committing changes, install the pre-commit hooks and run the tests:
68
+
69
+ ```bash
70
+ pre-commit install
71
+ pre-commit run --all-files
72
+ pytest
73
+ ```
74
+
75
+ Tests that depend on optional packages such as scikit-survival are skipped automatically when those packages are missing.
76
+
77
+ ## Usage
78
+
79
+ ### Python API
80
+
81
+ ```python
82
+ from gen_surv import generate, export_dataset, to_sksurv
83
+ from gen_surv.visualization import plot_survival_curve
84
+
85
+ sim = generate(
86
+ model="cphm",
87
+ n=100,
88
+ beta=0.5,
89
+ covariate_range=2.0,
90
+ model_cens="uniform",
91
+ cens_par=1.0,
92
+ )
93
+
94
+ plot_survival_curve(sim)
95
+ export_dataset(sim, "survival_data.rds")
96
+
97
+ # convert for scikit-survival
98
+ sks_dataset = to_sksurv(sim)
99
+ ```
100
+
101
+ See the [usage guide](https://gensurvpy.readthedocs.io/en/latest/getting_started.html) for more examples.
102
+
103
+ ### Command Line
104
+
105
+ Generate datasets and plots without writing Python code:
106
+
107
+ ```bash
108
+ python -m gen_surv dataset cphm --n 1000 -o survival.csv
109
+
110
+ python -m gen_surv visualize survival.csv --output survival_plot.png
111
+ ```
112
+
113
+ `visualize` accepts custom column names via `--time-col` and `--status-col` and can stratify by group with `--group-col`.
114
+
115
+ ## Supported Models
116
+
117
+ | Model | Description |
118
+ |-------|-------------|
119
+ | **CPHM** | Cox proportional hazards |
120
+ | **AFT** | Accelerated failure time (log-normal, log-logistic, Weibull) |
121
+ | **CMM** | Continuous-time multi-state Markov |
122
+ | **TDCM** | Time-dependent covariates |
123
+ | **THMM** | Time-homogeneous hidden Markov |
124
+ | **Competing Risks** | Multiple event types with cause-specific hazards |
125
+ | **Mixture Cure** | Models long-term survivors |
126
+ | **Piecewise Exponential** | Flexible baseline hazard via intervals |
127
+
128
+ More details on each algorithm are available in the [Algorithms](https://gensurvpy.readthedocs.io/en/latest/algorithms.html) page. For additional background, see the [theory guide](https://gensurvpy.readthedocs.io/en/latest/theory.html).
129
+
130
+ ## Documentation
131
+
132
+ Full documentation is hosted on [Read the Docs](https://gensurvpy.readthedocs.io/en/latest/). It includes installation instructions, tutorials, API references and a bibliography.
133
+
134
+ To build the docs locally:
135
+
136
+ ```bash
137
+ cd docs
138
+ make html
139
+ ```
140
+
141
+ Open `build/html/index.html` in your browser to view the result.
142
+
143
+ ## License
144
+
145
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
146
+
147
+ ## Citation
148
+
149
+ If you use **gen_surv** in your research, please cite the project using the metadata in [CITATION.cff](CITATION.cff).
150
+
151
+ ## Author
152
+
153
+ **Diogo Ribeiro** — [ESMAD - Instituto Politécnico do Porto](https://esmad.ipp.pt)
154
+
155
+ - ORCID: <https://orcid.org/0009-0001-2022-7072>
156
+ - Professional email: <dfr@esmad.ipp.pt>
157
+ - Personal email: <diogo.debastos.ribeiro@gmail.com>
158
+ - GitHub: [@DiogoRibeiro7](https://github.com/DiogoRibeiro7)
@@ -0,0 +1,104 @@
1
+ """Top-level package for ``gen_surv``.
2
+
3
+ This module exposes the main functions and provides access to the package version.
4
+ """
5
+
6
+ from importlib.metadata import PackageNotFoundError, version
7
+
8
+ from .aft import gen_aft_log_logistic, gen_aft_log_normal, gen_aft_weibull
9
+ from .bivariate import sample_bivariate_distribution
10
+ from .censoring import (
11
+ CensoringModel,
12
+ GammaCensoring,
13
+ LogNormalCensoring,
14
+ WeibullCensoring,
15
+ rexpocens,
16
+ rgammacens,
17
+ rlognormcens,
18
+ runifcens,
19
+ rweibcens,
20
+ )
21
+ from .cmm import gen_cmm
22
+ from .competing_risks import gen_competing_risks, gen_competing_risks_weibull
23
+ from .cphm import gen_cphm
24
+ from .export import export_dataset
25
+ from .interface import generate
26
+ from .mixture import cure_fraction_estimate, gen_mixture_cure
27
+ from .piecewise import gen_piecewise_exponential
28
+ from .sklearn_adapter import GenSurvDataGenerator
29
+ from .tdcm import gen_tdcm
30
+ from .thmm import gen_thmm
31
+
32
+ # Get package version
33
+ try:
34
+ __version__ = version("gen_surv")
35
+ except PackageNotFoundError: # pragma: no cover - fallback when package not installed
36
+ __version__ = "0.0.0"
37
+
38
+ # Visualization tools (requires matplotlib and lifelines)
39
+ try:
40
+ from .visualization import ( # noqa: F401
41
+ describe_survival,
42
+ plot_covariate_effect,
43
+ plot_hazard_comparison,
44
+ plot_survival_curve,
45
+ )
46
+
47
+ _has_visualization = True
48
+ except ImportError:
49
+ _has_visualization = False
50
+
51
+ # Optional scikit-survival integration
52
+ try:
53
+ from .integration import from_sksurv, to_sksurv # noqa: F401
54
+
55
+ _has_sksurv = True
56
+ except ImportError:
57
+ _has_sksurv = False
58
+
59
+ # Define exports
60
+ __all__ = [
61
+ # Main interface
62
+ "generate",
63
+ "__version__",
64
+ # Individual generators
65
+ "gen_cphm",
66
+ "gen_cmm",
67
+ "gen_tdcm",
68
+ "gen_thmm",
69
+ "gen_aft_log_normal",
70
+ "gen_aft_weibull",
71
+ "gen_aft_log_logistic",
72
+ "gen_competing_risks",
73
+ "gen_competing_risks_weibull",
74
+ "gen_mixture_cure",
75
+ "cure_fraction_estimate",
76
+ "gen_piecewise_exponential",
77
+ # Helper functions
78
+ "sample_bivariate_distribution",
79
+ "runifcens",
80
+ "rexpocens",
81
+ "rweibcens",
82
+ "rlognormcens",
83
+ "rgammacens",
84
+ "WeibullCensoring",
85
+ "LogNormalCensoring",
86
+ "GammaCensoring",
87
+ "CensoringModel",
88
+ "export_dataset",
89
+ "GenSurvDataGenerator",
90
+ ]
91
+
92
+ # Add optional exports if available
93
+ if _has_sksurv:
94
+ __all__.extend(["to_sksurv", "from_sksurv"])
95
+
96
+ if _has_visualization:
97
+ __all__.extend(
98
+ [
99
+ "plot_survival_curve",
100
+ "plot_hazard_comparison",
101
+ "plot_covariate_effect",
102
+ "describe_survival",
103
+ ]
104
+ )
@@ -0,0 +1,4 @@
1
+ from gen_surv.cli import app
2
+
3
+ if __name__ == "__main__":
4
+ app()