Skip to content

Commit 05c693b

Browse files
docs: update fix reference (#37)
1 parent 56e9e99 commit 05c693b

28 files changed

+593
-338
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ dist/
5050
# Temporary
5151
*.log
5252
*.tmp
53+
.hypothesis/

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ message: "If you use this software, please cite it using the metadata below."
55
preferred-citation:
66
type: software
77
title: "gen_surv"
8-
version: "1.0.3"
8+
version: "1.0.8"
99
url: "https://github.com/DiogoRibeiro7/genSurvPy"
1010
authors:
1111
- family-names: Ribeiro

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ poetry install
2828
- Easy integration with `pandas` and `NumPy`
2929
- Suitable for benchmarking survival algorithms and teaching
3030
- Accelerated Failure Time (Log-Normal) model generator
31+
- Mixture cure and piecewise exponential models
32+
- Competing risks generators (constant and Weibull hazards)
3133
- Command-line interface powered by `Typer`
3234

3335
## 🧪 Example
@@ -36,7 +38,7 @@ poetry install
3638
from gen_surv import generate
3739

3840
# CPHM
39-
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covar=2.0)
41+
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covariate_range=2.0)
4042

4143
# AFT Log-Normal
4244
generate(model="aft_ln", n=100, beta=[0.5, -0.3], sigma=1.0, model_cens="exponential", cens_par=3.0)
@@ -54,6 +56,18 @@ generate(model="tdcm", n=100, dist="weibull", corr=0.5,
5456
generate(model="thmm", n=100, qmat=[[0, 0.2, 0], [0.1, 0, 0.1], [0, 0.3, 0]],
5557
emission_pars={"mu": [0.0, 1.0, 2.0], "sigma": [0.5, 0.5, 0.5]},
5658
p0=[1.0, 0.0, 0.0], model_cens="exponential", cens_par=3.0)
59+
60+
# Mixture Cure
61+
generate(model="mixture_cure", n=100, cure_fraction=0.3, seed=42)
62+
63+
# Piecewise Exponential
64+
generate(
65+
model="piecewise_exponential",
66+
n=100,
67+
breakpoints=[1.0, 3.0],
68+
hazard_rates=[0.2, 0.5, 1.0],
69+
seed=0
70+
)
5771
```
5872

5973
## ⌨️ Command-Line Usage
@@ -75,6 +89,12 @@ python -m gen_surv dataset aft_ln --n 100 > data.csv
7589
| `gen_tdcm()` | Time-Dependent Covariate Model |
7690
| `gen_thmm()` | Time-Homogeneous Markov Model |
7791
| `gen_aft_log_normal()` | Accelerated Failure Time Log-Normal |
92+
| `gen_aft_log_logistic()` | AFT model with log-logistic baseline |
93+
| `gen_competing_risks()` | Competing risks with constant hazards |
94+
| `gen_competing_risks_weibull()` | Competing risks with Weibull hazards |
95+
| `gen_mixture_cure()` | Mixture cure model |
96+
| `cure_fraction_estimate()` | Estimate cure fraction |
97+
| `gen_piecewise_exponential()` | Piecewise exponential model |
7898
| `sample_bivariate_distribution()` | Sample correlated Weibull or exponential times |
7999
| `runifcens()` | Generate uniform censoring times |
80100
| `rexpocens()` | Generate exponential censoring times |

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
project = 'gen_surv'
1313
copyright = '2025, Diogo Ribeiro'
1414
author = 'Diogo Ribeiro'
15-
release = '1.0.3'
15+
release = '1.0.8'
1616

1717
# -- General configuration ---------------------------------------------------
1818
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ theory
3636
from gen_surv import generate
3737

3838
# CPHM
39-
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covar=2.0)
39+
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covariate_range=2.0)
4040

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

docs/source/theory.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,24 @@ This model is especially useful when the proportional hazards assumption is not
116116

117117
All models support censoring:
118118

119-
- **Uniform:** \( C_i \\sim U(0, \\text{cens\\_par}) \)
120-
- **Exponential:** \( C_i \\sim \\text{Exp}(\\text{cens\\_par}) \)
119+
- **Uniform:** \( C_i \sim U(0, \text{cens\_par}) \)
120+
- **Exponential:** \( C_i \sim \text{Exp}(\text{cens\_par}) \)
121+
122+
## 6. Competing Risks Models
123+
124+
These models simulate multiple mutually exclusive event types. Each cause has its
125+
own hazard function, and the observed status indicates which event occurred
126+
(1, 2, ...). The package includes constant-hazard and Weibull-hazard versions.
127+
128+
## 7. Mixture Cure Models
129+
130+
Mixture cure models assume a proportion of subjects are immune to the event. The
131+
generator mixes a logistic cure component with an exponential hazard for the
132+
uncured, returning a ``cured`` indicator column alongside the usual time and
133+
status.
134+
135+
## 8. Piecewise Exponential Model
136+
137+
This model divides the time axis into intervals defined by user-supplied
138+
breakpoints. Each interval has its own hazard rate, allowing flexible hazard
139+
shapes over time.

docs/source/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Generate datasets directly in Python:
2020
from gen_surv import generate
2121

2222
# Cox Proportional Hazards example
23-
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covar=2.0)
23+
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covariate_range=2.0)
2424
```
2525

2626
You can also generate data from the command line:

examples/run_cphm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
model_cens="uniform",
1111
cens_par=1.0,
1212
beta=0.5,
13-
covar=2.0,
13+
covariate_range=2.0,
1414
seed=42
1515
)
1616

fix_recommendations.md

Lines changed: 26 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,105 +2,45 @@
22

33
## Priority 1: Critical Fixes
44

5-
### 1. Fix `__init__.py` Import Issues
6-
7-
Update `gen_surv/__init__.py` to include missing imports:
8-
9-
```python
10-
# Add these imports
11-
from .aft import gen_aft_log_logistic
12-
from .competing_risks import gen_competing_risks, gen_competing_risks_weibull
13-
from .mixture import gen_mixture_cure, cure_fraction_estimate
14-
from .piecewise import gen_piecewise_exponential
15-
16-
# Update __all__ to include:
17-
__all__ = [
18-
# ... existing exports ...
19-
"gen_aft_log_logistic",
20-
"gen_competing_risks",
21-
"gen_competing_risks_weibull",
22-
"gen_mixture_cure",
23-
"cure_fraction_estimate",
24-
"gen_piecewise_exponential",
25-
]
26-
```
27-
28-
### 2. Add Missing Validators
29-
30-
Create validation functions in `validate.py`:
31-
32-
```python
33-
def validate_gen_aft_weibull_inputs(n, beta, shape, scale, model_cens, cens_par):
34-
# Add validation logic
35-
36-
def validate_gen_aft_log_logistic_inputs(n, beta, shape, scale, model_cens, cens_par):
37-
# Add validation logic
38-
39-
def validate_competing_risks_inputs(n, n_risks, baseline_hazards, betas, model_cens, cens_par):
40-
# Add validation logic
41-
```
42-
43-
### 3. Update CLI Integration
44-
45-
Modify `cli.py` to handle all available models:
46-
47-
```python
48-
# Add support for competing_risks, mixture, and piecewise models
49-
# Update parameter handling for each model type
50-
```
5+
- [x] **Fix `__init__.py` Import Issues**
6+
- Ensure missing imports for new generators are added and exported via `__all__`.
517

52-
## Priority 2: Version Consistency
53-
54-
### Update Version Numbers
8+
- [x] **Add Missing Validators**
9+
- Create validation helpers for AFT Weibull, AFT log-logistic, and competing risks generators.
5510

56-
1. **CITATION.cff**: Change version from "1.0.3" to "1.0.8"
57-
2. **docs/source/conf.py**: Change release from '1.0.3' to '1.0.8'
11+
- [x] **Update CLI Integration**
12+
- Support competing risks, mixture cure, and piecewise exponential models.
5813

59-
## Priority 3: Testing and Documentation
14+
## Priority 2: Version Consistency
6015

61-
### Add Missing Tests
16+
- [x] **Update Version Numbers**
17+
- `CITATION.cff` and `docs/source/conf.py` now reference version 1.0.8.
6218

63-
Create test files:
64-
- `tests/test_censoring.py`
65-
- `tests/test_mixture.py`
66-
- `tests/test_piecewise.py`
67-
- `tests/test_summary.py`
68-
- `tests/test_visualization.py`
19+
## Priority 3: Testing and Documentation
6920

70-
### Update Documentation
21+
- [x] **Add Missing Tests**
22+
- Added tests for censoring helpers, mixture cure, piecewise exponential, summary, and visualization.
7123

72-
1. Add competing risks, mixture, and piecewise models to `theory.md`
73-
2. Update examples in documentation to include new models
24+
- [x] **Update Documentation**
25+
- Documented competing risks, mixture cure, and piecewise exponential models.
7426

7527
## Priority 4: Code Quality Improvements
7628

77-
### Standardize Parameter Naming
78-
79-
- Consistently use `covariate_cols` instead of mixing `covar` and `covariate_cols`
80-
- Standardize return column names across all models
29+
- [x] **Standardize Parameter Naming**
30+
- Replaced the `covar` parameter with `covariate_range` and standardized return columns to `X0`.
8131

82-
### Add Type Hints
83-
84-
Complete type hints for all public functions, especially in:
85-
- `mixture.py`
86-
- `piecewise.py`
87-
- `summary.py`
32+
- [x] **Add Type Hints**
33+
- Completed type hints for public functions in `mixture.py`, `piecewise.py`, and `summary.py`.
8834

8935
## Verification Steps
36+
- [x] `python -c "from gen_surv import gen_aft_log_logistic, gen_competing_risks"`
37+
- [x] `python -m gen_surv dataset competing_risks --n 10`
38+
- [x] `pytest -q`
39+
- [x] `python scripts/check_version_match.py`
40+
- [x] `sphinx-build docs/source docs/build`
9041

91-
After implementing fixes:
92-
93-
1. **Test imports**: `python -c "from gen_surv import gen_aft_log_logistic, gen_competing_risks"`
94-
2. **Test CLI**: `python -m gen_surv dataset competing_risks --n 10`
95-
3. **Run full test suite**: `poetry run pytest`
96-
4. **Check version consistency**: `python scripts/check_version_match.py`
97-
5. **Build docs**: `poetry run sphinx-build docs/source docs/build`
42+
## Status
9843

99-
## Impact Assessment
44+
All fix recommendations have been implemented in version 1.0.8.
10045

101-
These fixes will:
102-
- ✅ Eliminate ImportError exceptions for users
103-
- ✅ Make all models accessible via public API
104-
- ✅ Ensure CLI works for all supported models
105-
- ✅ Improve user experience and API consistency
106-
- ✅ Maintain backward compatibility
46+
Verified as of commit `7daa3e1`.

gen_surv/__init__.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from .cmm import gen_cmm
1414
from .tdcm import gen_tdcm
1515
from .thmm import gen_thmm
16-
from .aft import gen_aft_log_normal, gen_aft_weibull
16+
from .aft import gen_aft_log_normal, gen_aft_weibull, gen_aft_log_logistic
17+
from .competing_risks import gen_competing_risks, gen_competing_risks_weibull
18+
from .mixture import gen_mixture_cure, cure_fraction_estimate
19+
from .piecewise import gen_piecewise_exponential
1720

1821
# Helper functions
1922
from .bivariate import sample_bivariate_distribution
@@ -25,8 +28,9 @@
2528
plot_survival_curve,
2629
plot_hazard_comparison,
2730
plot_covariate_effect,
28-
describe_survival
31+
describe_survival,
2932
)
33+
3034
_has_visualization = True
3135
except ImportError:
3236
_has_visualization = False
@@ -40,15 +44,19 @@
4044
# Main interface
4145
"generate",
4246
"__version__",
43-
4447
# Individual generators
4548
"gen_cphm",
4649
"gen_cmm",
4750
"gen_tdcm",
4851
"gen_thmm",
4952
"gen_aft_log_normal",
5053
"gen_aft_weibull",
51-
54+
"gen_aft_log_logistic",
55+
"gen_competing_risks",
56+
"gen_competing_risks_weibull",
57+
"gen_mixture_cure",
58+
"cure_fraction_estimate",
59+
"gen_piecewise_exponential",
5260
# Helpers
5361
"sample_bivariate_distribution",
5462
"runifcens",
@@ -57,10 +65,11 @@
5765

5866
# Add visualization tools to __all__ if available
5967
if _has_visualization:
60-
__all__.extend([
61-
"plot_survival_curve",
62-
"plot_hazard_comparison",
63-
"plot_covariate_effect",
64-
"describe_survival"
65-
])
66-
68+
__all__.extend(
69+
[
70+
"plot_survival_curve",
71+
"plot_hazard_comparison",
72+
"plot_covariate_effect",
73+
"describe_survival",
74+
]
75+
)

0 commit comments

Comments
 (0)