Skip to main content

A python package for survival analysis

Project description

surpyval logo

SurPyval - Survival Analysis in Python

actions PyPI version Python Version Documentation Status DOI

Yet another Python survival analysis tool.

This is another pure python survival analysis tool so why was it needed? The intent of this package was to closely mimic the scipy API as close as possible with a simple .fit() method for any type of distribution (parametric or non-parametric); other survival analysis packages don't completely mimic that API. Further, there is currently (at the time of writing) no pacakage that can take an arbitrary comination of observed, censored, and truncated data. Finally, surpyval is unique in that it can be used with multiple parametric estimation methods. This allows for an analyst to determine a distribution for the parameters if another method fails. The parametric methods available are Maximum Likelihood Estimation (MLE), Probability Plotting (MPP), Mean Square Error (MSE), Method of Moments (MOM), and Maximum Product of Spacing (MPS). Surpyval can, for each type of estimator, take the following types of input data:

Method Para/Non-Para Observed Censored Truncated
MLE Parametric Yes Yes Yes
MPP Parametric Yes Yes Limited
MSE Parametric Yes Yes Limited
MOM Parametric Yes No No
MPS Parametric Yes Yes No
Kaplan-Meier Non-Parametric Yes Right only Left only
Nelson-Aalen Non-Parametric Yes Right only Left only
Fleming-Harrington Non-Parametric Yes Right only Left only
Turnbull Non-Parametric Yes Yes Yes

SurPyval also offers many different distributions for users, and because of the flexible implementation adding new distributions is easy. Further, the power of SurPyval lay in the robust parameter estimation, as such, some distributions, those that are supported on the half real line, can be offset to make a three- or four-parameter version. The currently available distributions are:

Distribution Offsetable
Weibull Yes
Normal No
LogNormal Yes
Gamma Yes
Beta No
Uniform No
Exponential Yes
Exponentiated Weibull Yes
Gumbel No
Logistic No
LogLogistic Yes

This project spawned from a Reliaility Engineering project; due to the history of reliability engineers estimating parameters from a probability plot. SurPyval has continued this tradition to ensure that any parametric distribution can have the estimate plotted on a probability plot. These visualisations enable an analyst to get a sense of the goodness of fit of the parametric distribution with the non-parametric distribution.

Install and Quick Intro

SurPyval can be installed via pip using the PyPI repository

pip install surpyval

If you're familiar with survival analysis, and Weibull plotting, the following is a quick start.

from surpyval import Weibull
from surpyval.datasets import load_bofors_steel

# Fetch some data that comes with SurPyval
data = load_bofors_steel()

x = data['x']
n = data['n']

model = Weibull.fit(x=x, n=n, offset=True)
model.plot();

Weibull Data and Distribution

Documentation

SurPyval is well documented, and improving, at the main documentation.

Development

Dependencies

pip install -r requirements_dev.txt

Testing

Run the testing suite by simply executing:

pytest

or use coverage to get a coverage report:

coverage run -m pytest  # Run pytest under coverage's watch
coverage report         # Print coverage report
coverage html           # Make a html coverage report (really useful), open htmlcov/index.html

Pre-commit

  • Pip install pre-commit (it's in requirements_dev.txt anyways)
  • Run pre-commit install which sets up the git hook scripts
  • If you'd like, run pre-commit run --all-files to run the hooks on all files
  • When you go to commit, it will only proceed after all the hooks succeed

Contact

Email derryn if you want any features or to see how SurPyval can be used for you.

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

surpyval-0.11.1.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

surpyval-0.11.1-py3-none-any.whl (2.0 MB view details)

Uploaded Python 3

File details

Details for the file surpyval-0.11.1.tar.gz.

File metadata

  • Download URL: surpyval-0.11.1.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for surpyval-0.11.1.tar.gz
Algorithm Hash digest
SHA256 12c495bd167f4f0f8c1498818a788e3fe484b352f0cccc09a4bf05f5e1333103
MD5 3202c31614b7d2fa8a03e1b2ec2ecd78
BLAKE2b-256 d2b727446b2d87b4692d931151faa2da7ef67addc5f7ba08809812a1fa404275

See more details on using hashes here.

File details

Details for the file surpyval-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: surpyval-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for surpyval-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1b8b8e6046a490288a6a7c3ced89c9674185c427f1c99a055bb0aa4652b2b3c
MD5 c6356c784381982abd34aed13af1f029
BLAKE2b-256 3ddaba63bf79b6c33909640fcd5b75304fccb89cc30243293831e35ebfe92319

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