Skip to main content

pypi version Tests documentation codecov DOI

Discrete Time Survival Analysis

PyDTS is a Python package designed for discrete-time survival analysis with competing risks, offering tools for model fitting, evaluation, and simulation.

For details, usage examples, and API information - check out the package documentation

PyDTS offers:

  • Discrete-time competing-risks regression models.
  • Automated procedures for hyperparameter tuning.
  • Sure Independence Screening methods for feature selection.
  • Model evaluation metrics for predictive accuracy and calibration.
  • Simulation tools for generating synthetic datasets for research and testing.

Additional simulations and illustrative examples are available in Meir and Gorfine (2025), Discrete-Time Competing-Risks Regression with or without Penalization, Biometrics (2025), and in the accompanying Github Repository

Installation

PyDTS can be installed using PyPI as follows:

pip install pydts

Dependencies

PyDTS supports Python versions 3.9–3.13.

The package requires the following dependencies (with version constraints chosen for compatibility across Python and NumPy/SciPy releases):

  • NumPy

    • Python 3.9: >=1.26,<2.1
    • Python 3.10: >=1.26,<2.3
    • Python 3.11–3.13: >=1.26 (including NumPy 2.x)
  • SciPy

    • Python 3.9: >=1.13,<1.14
    • Python 3.10: >=1.14,<1.16
    • Python 3.11–3.13: >=1.15
  • pandas >=2.2.2

  • scikit-learn >=1.6

  • statsmodels >=0.14.2

  • lifelines >=0.27

  • tqdm >=4.66

  • psutil >=5.9

  • seaborn >=0.13

  • formulaic >=1.0

All dependencies are installed automatically when you install PyDTS.

Quick Start

The following example demonstrates how to generate synthetic data and fit a TwoStagesFitter model.

Detailed definitions and explanations are available in the methods section of the documentation.

The function generate_quick_start_df simulates a dataset with the following defaults:

  • Sample size: n_patients=10000
  • Covariates: n_cov=5 independent covariates, each drawn from Uniform(0,1) distribution
  • Competing events: j_events=2 event types
  • Time scale: d_times=14 discrete time intervals
  • Hazard coefficients (default values):
    • $\alpha_{1t}$ = −1 − 0.3 * log(t)
    • $\alpha_{2t}$ = −1.75 − 0.15 * log(t)
    • $\beta_1$ = −log([0.8, 3, 3, 2.5, 2])
    • $\beta_2$ = −log([1, 3, 4, 3, 2])

For each patient, a censoring time $C$ is drawn from Uniform{1, ..., 14}. The observed time is defined as $X = min(T, C)$, where $T$ is the event time which is sampled based on the covariates of each patient and the hazard coefficients. If censoring occurs before the event ($C < T$), the event type is set to $J = 0$.

Once the dataset is generated, you can fit a TwoStagesFitter to the data (without columns $C$ and $T$ which are not observed in practice).

You can generate synthetic data and fit your first TwoStagesFitter model with the following code:

from pydts.fitters import TwoStagesFitter
from pydts.examples_utils.generate_simulations_data import generate_quick_start_df

# Generate a synthetic dataset with 10,000 patients,
# 5 covariates, 14 discrete time intervals, and 2 competing events
patients_df = generate_quick_start_df(n_patients=10000, n_cov=5, d_times=14, j_events=2, pid_col='pid', seed=0)

# Initialize and fit the discrete-time competing-risk model
fitter = TwoStagesFitter()
fitter.fit(df=patients_df.drop(['C', 'T'], axis=1))

# Display model summary
fitter.print_summary()

Citations

If you found PyDTS software useful to your research, please cite the papers:

@article{Meir_PyDTS_2022,
    author = {Meir, Tomer and Gutman, Rom, and Gorfine, Malka},
    doi = {10.48550/arXiv.2204.05731},
    title = {{PyDTS: A Python Package for Discrete Time Survival Analysis with Competing Risks}},
    url = {https://arxiv.org/abs/2204.05731},
    year = {2022}
}

@article{Meir_Gorfine_DTSP_2025,
    author = {Meir, Tomer and Gorfine, Malka},
    doi = {10.1093/biomtc/ujaf040},
    title = {{Discrete-Time Competing-Risks Regression with or without Penalization}},
    year = {2025},
    journal = {Biometrics},
    volume = {81},
    number = {2},
    url = {https://academic.oup.com/biometrics/article/81/2/ujaf040/8120014},
}

and please consider starring the project on GitHub

How to Contribute

  1. Open Github issues to suggest new features or to report bugs\errors.
  2. Provide feedback on the documentation.
  3. Contact Tomer or Rom if you want to add a usage example to the documentation.
  4. If you want to become a developer (thank you, we appreciate it!) - please contact Tomer or Rom for developers' on-boarding.

Tomer Meir: tomer1812@gmail.com, Rom Gutman: rom.gutman1@gmail.com

Running Tests Locally

To run the test suite on your local machine, follow these steps:

  1. Clone the repository
git clone https://github.com/tomer1812/pydts.git
cd pydts
  1. Install the package in editable mode
pip install -e .
  1. Run the test suite with Poetry
pip install poetry
poetry run pytest

Metadata

Release files for pydts 0.10.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydts 0.10.3
File Size Uploaded Provenance
pydts-0.10.3.tar.gz 1.4 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pydts 0.10.3
File Interpreter ABI Platform
pydts-0.10.3-py3-none-any.whl Python 3 none any Details

Total release size: 2.8 MB

Release files / pydts-0.10.3.tar.gz

Download URL pydts-0.10.3.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
8646e4bc13b8086981abcbd8b6e75e3cd2f46a755e7531e93ec725ed70f347d9
BLAKE2b-256 checksum
How to use checksums
b59fa825214be6e8fbb89a67f3a08f41cefa0316e6b385f4e78fa9d5d406aa44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.19 Darwin/24.6.0

Release files / pydts-0.10.3-py3-none-any.whl

Download URL pydts-0.10.3-py3-none-any.whl
Size 1.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b1e72dc8221ddb5a3011369d80b8ec0b382f9f98f4cb547478ef53f155f099d9
BLAKE2b-256 checksum
How to use checksums
bb871dc5678838c85fd5872fb643dae29ccca5c96f876580c2d5701aec037946
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.19 Darwin/24.6.0

Security for pydts 0.10.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.3 This release

2 release files No provenance

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