PyMSM
PyMSM: Python package for Competing Risks and Multi-State models for Survival Data - Published in JOSS (2022)
Science Score: 98.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 8 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: nature.com, joss.theoj.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Scientific Fields
Repository
Basic Info
- Host: GitHub
- Owner: hrossman
- License: mit
- Language: Jupyter Notebook
- Default Branch: main
- Size: 3.04 MB
Statistics
- Stars: 53
- Watchers: 1
- Forks: 7
- Open Issues: 5
- Releases: 1
Metadata Files
README.md
Multistate competing risk models in Python
Read the Docs
For details, read the JOSS paper
Hagai Rossman, Ayya Keshet, Malka Gorfine 2022
PyMSM is a Python package for fitting competing risks and multistate models, with a simple API which allows user-defined model, predictions at a single or population sample level, statistical summaries and figures.
Features include:
- Fit a Competing risks Multistate model based on survival analysis (time-to-event) models.
- Deals with right censoring, competing events, recurrent events, left truncation, and time-dependent covariates.
- Run Monte-carlo simulations for paths emitted by the trained model and extract various summary statistics and plots.
- Load or configure a pre-defined model and run path simulations.
- Modularity and compatibility for different time-to-event models such as Survival Forests and other custom models.
Installation
console
pip install pymsm
Requires Python >=3.8.
Alternatively if you want to work with the latest development version, you can also directly install it from GitHub.
To do that, you will need to
1. Clone the repository to REPO_FOLDER (choose your own location)
2. Got to the location of the repository cd $REPO_FOLDER (Note! Not the pymsm folder, but the one above)
3. Run pip install -e pymsm. This imports the package for your Python interpreter
Quick example
```py linenums="1"
Load data (See Rotterdam example for full details)
from pymsm.datasets import preprotterdam dataset, stateslabels = prep_rotterdam()
Define terminal states
terminal_states = [3]
Init MultistateModel
from pymsm.multistatecompetingrisksmodel import MultiStateModel multistatemodel = MultiStateModel(dataset,terminal_states)
Fit model to data
multistatemodel.fit()
Run Monte-Carlo simulation and sample paths
mcs = multistatemodel.runmontecarlosimulation( samplecovariates = dataset[0].covariates.values, originstate = 1, currenttime = 0, maxtransitions = 2, nrandomsamples = 10, printpaths=True) ```
mermaid
stateDiagram-v2
s1 : (1) Primary surgery
s2 : (2) Disease recurrence
s3 : (3) Death
s1 --> s2: 1518
s1 --> s3: 195
s2 --> s3: 1077
Full examples
Background and Motivation
Multi-state data are common, and could be used to describe trajectories in diverse health applications; such as describing a patient's progression through disease stages or a patient’s path through different hospitalization states. When faced with such data, a researcher or clinician might seek to characterize the possible transitions between states, their occurrence probabilities, or to predict the trajectory of future patients - all conditioned on various baseline and time-varying individual covariates. By fitting a multi-state model, we can learn the hazard for each specific transition, which would later be used to predict future paths. Predicting paths could be used at a single patient level, for example predict how long until a cancer patient will be relapse-free given his current health status, or at what probability will a patient end a trajectory at any of the possible states; and at the population level, for example predicting how many patients which arrive at the emergency-room will need to be admitted, given their covariates.
Capabilities
PyMSM is a Python package for fitting multi-state models, with a simple API which allows user-defined models, predictions at a single or population sample level, and statistical summaries and figures.
Features of this software include:
- Fitting a Competing risks Multistate model based on various types of survival analysis (time-to-event) such as Cox proportional hazards models or machine learning models, while taking into account right censoring, competing events, recurrent events, left truncation, and time-dependent covariates.
- Running Monte-carlo simulations (in parallel computation) for paths emitted by the trained model and extracting various summary statistics and plots.
- Loading or configuring a pre-defined model and generating simulated data in terms of random paths using model parameters, which could be highly useful as a research tool.
- Modularity and compatibility for different time-to-event models such as Survival Forests and other custom ML models provided by the user.
The package is designed to allow modular usage by both experienced researchers and non-expert users. In addition to fitting a multi-state model for a given data - PyMSM allows the user to simulate trajectories, thus creating a multi-state data-set, from a predefined model. This could be a valuable research tool - both for sharing sensitive simulated individual data and as a tool for any downstream task which needs individual trajectories.
Citation
If you found this library useful in academic research, please cite:
bibtex
@article{Rossman2022, doi = {10.21105/joss.04566},
url = {https://doi.org/10.21105/joss.04566},
year = {2022},
author = {Hagai Rossman and Ayya Keshet and Malka Gorfine},
title = {PyMSM: Python package for Competing Risks and Multi-State models for Survival Data},
journal = {Journal of Open Source Software} }
Also consider starring the project on GitHub
This project is based on methods first introduced by the authors of Roimi et. al. 2021.
Original R code by Jonathan Somer, Asaf Ben Arie, Rom Gutman, Uri Shalit & Malka Gorfine available here.
Also see Rossman & Meir et. al. 2021 for an application of this model on COVID-19 hospitalizations data.
Owner
- Name: Hagai_Rossman
- Login: hrossman
- Kind: user
- Company: Weizmann institute of science
- Website: https://hrossman.github.io/
- Twitter: H_Rossman
- Repositories: 27
- Profile: https://github.com/hrossman
PhD student at Weizmann Institute of Science. Digging through health data.
JOSS Publication
PyMSM: Python package for Competing Risks and Multi-State models for Survival Data
Authors
Department of Computer Science and Applied Mathematics, Weizmann Institute of Science, Rehovot, Israel, Department of Molecular Cell Biology, Weizmann Institute of Science, Rehovot, Israel
Tags
multistate models survival analysis competing risksCitation (CITATION.cff)
# YAML 1.2
---
authors:
- family-names: Rossman
given-names: Hagai
- family-names: Keshet
given-names: Ayya
- family-names: Gorfine
given-names: Malka
cff-version: 1.2.0
doi: "https://doi.org/10.5281/zenodo.6300873"
license: MIT
message: "If you use this software, please cite it using these metadata."
repository-code: "https://github.com/hrossman/pymsm"
title: PyMSM, Multistate modeling in Python
date-released: 2022-02-27
...
GitHub Events
Total
- Watch event: 10
- Pull request event: 1
- Fork event: 4
Last Year
- Watch event: 10
- Pull request event: 1
- Fork event: 4
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| HR | h****n@g****m | 401 |
| ayya-keshet | a****t@g****m | 70 |
| Stefano Coretta | s****a@g****m | 1 |
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 8
- Total pull requests: 60
- Average time to close issues: about 2 months
- Average time to close pull requests: about 11 hours
- Total issue authors: 5
- Total pull request authors: 5
- Average comments per issue: 0.75
- Average comments per pull request: 0.05
- Merged pull requests: 55
- Bot issues: 0
- Bot pull requests: 2
Past Year
- Issues: 0
- Pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- CamDavidsonPilon (4)
- ehodneland (1)
- stefanocoretta (1)
- maurofaccin (1)
- bbb801 (1)
Pull Request Authors
- hrossman (39)
- ayya-keshet (16)
- dependabot[bot] (2)
- smgtkn (2)
- stefanocoretta (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 298 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 10
- Total maintainers: 2
pypi.org: pymsm
Multstate modeling in Python
- Homepage: https://hrossman.github.io/pymsm/
- Documentation: https://hrossman.github.io/pymsm/
- License: MIT
-
Latest release: 0.1.7
published almost 4 years ago
Rankings
Dependencies
- 121 dependencies
- coverage ^6.3.2 develop
- ipykernel ^6.9.1 develop
- mkdocs-material ^8.2.1 develop
- mkdocstrings ^0.18.0 develop
- mknotebooks ^0.7.1 develop
- pre-commit ^2.17.0 develop
- pytest ^7.0.1 develop
- pytest-cov ^3.0.0 develop
- pytkdocs ^0.16.0 develop
- scikit-survival ^0.17.0 develop
- tabulate ^0.8.9 develop
- joblib ^1.1.0
- lifelines ^0.26.4
- matplotlib ^3.5.1
- numpy ^1.22.2
- pandas ^1.4.1
- python ^3.8
- scikit-learn ^1.0.2
- tabulate ^0.8.9
- tqdm ^4.62.3
- actions/checkout v2 composite
- psf/black stable composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- actions/checkout v2 composite
- actions/upload-artifact v1 composite
- openjournals/openjournals-draft-action master composite
- actions/checkout v2 composite
- actions/setup-python v1 composite
- actions/checkout master composite
- actions/setup-python master composite
- codecov/codecov-action v2 composite