SurPyval - Survival Analysis in Python
SurPyval is a Python package for survival analysis: the statistics of how long things last. The “thing” can be a bearing, a patient, a loan, a recession or a marathon runner, and the “time” can be hours, cycles, kilometres or dollars. What makes these problems different from ordinary statistics is that the data is almost never complete. Some units (items, subjects) have not had the event (have not failed, died or relapsed) when the study ends (censoring), some were only inspected now and then, and some never reached your data set at all because of how it was collected (truncation). SurPyval is built around handling every one of those situations correctly, in any combination, with one consistent interface.
The package grew out of reliability engineering, so it has the tools an engineer expects (probability plots, offsets, B-lives, accelerated life tests, burn-in and warranty calculations, repairable systems, degradation), alongside the tools of biostatistics and econometrics (Kaplan-Meier, Cox regression, competing risks, frailty, predictive metrics).
Installation
SurPyval needs Python 3.11 or later and installs with pip:
$ pip install surpyval
To work on SurPyval itself, see Contributing.
Reliafy is a hosted, browser-based app built on SurPyval, for fitting life distributions, regression and recurrent-event models to censored data without writing code.
Where to start
New to survival analysis? Start with Survival Analysis from Scratch. It assumes no background and explains censoring, the survival and hazard functions, the Kaplan-Meier estimate by hand, a Weibull fit, comparing groups and regression, with one engineering and one medical example.
New to SurPyval? Read the Quickstart. In ten minutes it fits a first model, shows why censoring matters, and gives a small example of every area of the package.
Not sure which model your data needs? Choosing a Model asks one yes-or-no question at a time: the shape of the problem, how to write each unit’s record, and what you want to know, ending at the call to make.
New to survival data, or not sure whether your data is censored or truncated? Read Types of Data. Getting this right matters more than any choice of model. The data model then lists every letter a row of data can carry (time, censoring, counts, entry, unit, event type, state, terminal flag, measurements, covariates, weights) and which models take which.
Have data in a spreadsheet, a list of failures and survivors, or a maintenance log? Data Wrangling Examples shows how to turn it into the
x,c,n,tarrays every fitter takes, and Conventions defines those arrays exactly.Used to other words for these ideas (event or failure, subject or unit, survival or reliability, right censored or suspended)? The Glossary maps the engineering, medical and statistical vocabularies to each other and to SurPyval’s names.
How the documentation is organised
The pages are in five groups, in the menu on the left:
Quickstart & Intro: the pages above, plus Handy References - Aide-mémoire, a one-page summary of the functions of a distribution and how they relate.
Survival Analysis: the theory pages. Each explains a family of methods from first principles: the problem it solves, the mathematics, how to read the results, what can go wrong and when to use something else. They are written so that you can learn the methods from them.
SurPyval Modelling: the how-to pages. Each shows how to do that analysis in SurPyval, with worked examples whose output is computed when the documentation is built, so it always matches the current version. It also includes Example Applications, complete examples from several fields. Each theory page links to its how-to page and the other way round.
SurPyval: the API reference (API), with every class, function and argument, the v0.28 (14 November 2026) and the Deprecation Policy.
Community Guidelines: where to get help, how to report a problem and how to contribute.
What SurPyval covers
Every model is created the same way: a fitter (surv.Weibull,
surv.KaplanMeier, surv.CoxPH, …) has a fit() method that
takes your data and returns a fitted model, which you then ask for
survival probabilities, hazards, quantiles, confidence bounds, plots and
so on.
Area |
What is in it |
Theory / how-to |
|---|---|---|
Non-parametric estimation |
Kaplan-Meier, Nelson-Aalen, Fleming-Harrington and Turnbull estimators with confidence bounds and bands; the log-rank test; restricted mean survival time; success-run (zero-failure) testing. |
Non-Parametric Estimation / Non-Parametric SurPyval Modelling |
Parametric distributions |
Continuous lifetime distributions (Weibull, Exponential, Gamma,
LogNormal, LogLogistic, Gumbel, Normal, Logistic, Exponentiated
Weibull, Beta, Rayleigh, Uniform, …) and discrete ones (Geometric,
Poisson, Binomial, Negative Binomial, Beta-Geometric, discrete
Weibull), fitted by any of the five estimation methods in the table
below. Offsets (the three-parameter Weibull), limited failure
populations and zero-inflation; mixture models; your own
distribution from a cumulative hazard; the Royston-Parmar flexible
spline model; automatic choice of distribution with |
|
Regression |
Proportional hazards (Cox, with strata and time-varying covariates, and parametric), accelerated failure time, accelerated life with life-stress relationships (power law, Eyring, exponential/Arrhenius and others), proportional odds, additive hazards, Buckley-James, shared frailty; Brier score and time-dependent AUC for validating predictions. |
|
Competing risks |
Units that can fail, or subjects that can have an event, from one of several causes (failure modes, causes of death): cumulative incidence (Aalen-Johansen), parametric cause-specific models, cause-specific Cox regression, Fine-Gray subdistribution regression and Gray’s test. |
Competing Risks Analysis / Competing Risks SurPyval Modelling |
Multi-state models |
Units that move between several states (healthy, ill, dead; working, degraded, failed): Aalen-Johansen transition and state occupation probabilities with delayed entry, and a Cox model of each transition with the probabilities it predicts. |
|
Recurrent events |
Events that happen again and again to the same unit (a repairable item that keeps failing, a patient with repeated admissions): the mean cumulative function, homogeneous and non-homogeneous Poisson processes (Crow-AMSAA, Duane, Cox-Lewis), software reliability growth (Goel-Okumoto, the S-shaped models, Musa-Okumoto), imperfect repair (Kijima, G1, ARA, ARI), trend tests, proportional-intensity regression (parametric, and the Andersen-Gill, Prentice-Williams-Peterson and Wei-Lin-Weissfeld models with robust standard errors), and whether a corrective action changed the failure rate. |
Recurrent Event Analysis / Recurrent Event Modelling with SurPyval; Recurrent Event Regression Analysis / Recurrent Event Regression Modelling with SurPyval; Intervention Analysis with SurPyval |
Degradation |
Measurements that drift towards a failure threshold: general path models, Wiener and Gamma processes, destructive degradation, remaining useful life of a monitored unit, and accelerated and step-stress degradation tests. |
|
Multivariate |
Dependent lifetimes joined by a copula (Clayton, Frank, Gumbel, Gaussian, independence), with censored and truncated margins. |
Multivariate Analysis / Multivariate Modelling with SurPyval |
Test planning |
Planning tests before they are run: reliability and MTBF demonstration tests (fixed-length and sequential), the units and test length to estimate a B-life to a given precision, optimum and compromise accelerated life test plans, the sample size and power of a log-rank comparison, and the power of a comparison of failure rates before and after a change. |
Almost every fitted model can be saved to a dictionary or a JSON file and
restored with surv.from_dict or surv.from_json (see Conventions
for what a restored model keeps, and the few models that cannot be saved). A
survival tree and a random survival forest are in surpyval.ml (see
Machine Learning).
Estimating a single distribution
SurPyval is unusual in how many ways it can estimate the parameters of a distribution. Most packages offer maximum likelihood, and perhaps probability plotting; SurPyval grew out of reproducing the probability plotting of engineering practice and found along the way that there are many ways to estimate parameters, each with its own strengths. The methods, and the data each can use, are:
Method |
Para/Non-Para |
Observed |
Censored |
Truncated |
|---|---|---|---|---|
Maximum Likelihood (MLE) |
Parametric |
Yes |
Yes: left, right and interval |
Yes: left and right, a different value for each observation if needed |
Maximum Product Spacing (MPS) |
Parametric |
Yes |
Left and right; not interval |
Yes, but one common |
Probability Plotting (MPP) |
Parametric |
Yes |
Right; left and interval only with |
Left (with the Kaplan-Meier, Nelson-Aalen, Fleming-Harrington or
Turnbull heuristic); right only with |
Mean Square Error (MSE) |
Parametric |
Yes |
Yes: left, right and interval |
No |
Method of Moments (MOM) |
Parametric |
Yes |
No |
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: left, right and interval |
Yes: left and right |
Maximum likelihood is the default (how="MLE") and, with Turnbull for a
non-parametric view, handles every combination of data. The other methods
have their own uses: probability plotting is the traditional engineering
method and gives the familiar straight-line plot; maximum product spacing
is particularly good for offset distributions and distributions with a
finite bound, where the likelihood can be unbounded; and the method of
moments is quick for complete data. Some distributions do not support every
method (probability plotting needs a distribution that can be drawn as a
straight line, and discrete distributions cannot use MPS). Whenever a
method cannot use your data, SurPyval raises an error saying so rather than
silently ignoring part of it. The methods are explained in
Parametric Estimation and Non-Parametric Estimation, and
Types of Data has the same table split by type of censoring and
truncation.
Stability and deprecation
A public name is never removed without warning. When one is renamed or
removed, the old name keeps working for at least one release with a
warning that names its replacement and the release that removes it; after
that, using it raises an error that still names the replacement. Names
starting with an underscore and the surpyval.beta tier may change
without notice, and every deprecation and removal is listed in the
v0.28 (14 November 2026). SurPyval is not yet at 1.0, so releases come often and a
result can change in any release when it is corrected (always under
Changed or Fixed in the changelog). The details are in the
Deprecation Policy.
A word of encouragement
Becoming a competent survival analyst depends on a strong understanding of censoring, truncation and observations, together with a solid understanding of the distributions used to describe lifetimes. Recognising that a real situation is censored or truncated is what keeps an analysis from going wrong, and it can be surprisingly difficult; Types of Data is the place to build that skill. A good understanding of the distributions lets you reason about the process that generated your data, and so choose an appropriate model, if any, for your problem. Survival analysis is an extremely powerful, and thoroughly interesting, tool, so don’t give up; or if you do give up, do the survival statistics on it.
Contents:
Quickstart & Intro
- Quickstart
- Choosing a Model
- Survival Analysis from Scratch
- What is time-to-event data?
- Why you can’t just average the times
- Censoring: knowing only part of the answer
- Truncation: units you never saw
- Three ways to describe how long things last
- Kaplan-Meier by hand
- How sure are we? Bounds
- Fitting a Weibull distribution
- Comparing two groups
- Where regression comes in
- Where to go next
- Types of Data
- The data model
- Conventions
- Glossary
- Design Principles
- Handy References - Aide-mémoire
- Data Wrangling Examples
- One record per item
- From a DataFrame
- One dataset, several analyses
- Updating a dataset as items age
- Comparing sites, arms or product lines
- Combining every input type in one fit
- Same data, whichever format you have it in
- Combining, comparing, rescaling and resampling
- Truncation, four ways
- From dates to durations
- Counts found at inspections
- Recurrent events from a maintenance log
- Format converters
- Weighted Data
- What a weight is
- When to use
wand whenn - Why the intervals change
- A worked example
- Bootstrap bounds of a weighted fit
- Interval censored data: the weighted Turnbull estimate
- Comparing weighted groups
- Competing-risks regressions
- Distributional and Royston-Parmar regression with weights
- Competing risks: weighted cumulative incidence
- Penalised fits with weights
- What a weighted fit will not do
- The formulas
- Translating from lifelines and R
Survival Analysis
- Non-Parametric Estimation
- Parametric Estimation
- Regression Analysis
- Competing Risks Analysis
- Recurrent Event Analysis
- Recurrent Event Regression Analysis
- Degradation Analysis
- Choosing an approach
- Notation
- The path model
- The two-stage (moments) estimate
- The REML estimate
- Stress on the life: a regression on the pseudo failure times
- Stress on the mechanism: path parameters that depend on stress
- The clock
- Estimating the acceleration
- Life and prediction on the clock
- The Wiener process
- The Gamma process
- Stress and time-varying stress
- Choosing between a path and a process
- Joint Models
- Landmark Analysis
- Multivariate Analysis
SurPyval Modelling
- Non-Parametric SurPyval Modelling
- Parametric SurPyval Modelling
- Available distributions
- Complete Data
- Using censored data
- Using truncated data
- Offsets
- A caution: offset parameters can be unidentifiable
- Fixing parameters
- Modelling with arbitrary input
- Using alternate estimation methods
- Mixture Models
- Limited Failure Population
- Zero-Inflated Modelling
- Flexible parametric (Royston-Parmar)
- Discrete Distributions
- Confidence Intervals
- Carrying a fit’s uncertainty forward
- Forecasting failures in service
- Creating a custom Distribution
- Hazard Ratio
- Bayesian Fitting with SurPyval
- Pooling Rates Across Sources
- Regression Modelling with SurPyval
- Choosing a regression model family
- Semi-Parametric — Cox Proportional Hazards
- Semi-Parametric — Buckley-James (AFT)
- Semi-Parametric — Censored Quantile Regression
- Semi-Parametric — Additive Hazards
- Non-Parametric — Aalen’s Additive Hazards
- Parametric Proportional Hazards (PH)
- Accelerated Failure Time (AFT)
- Flexible parametric (spline) regression
- Proportional Odds (PO)
- Semi-Parametric — Proportional Odds
- Confidence Bounds
- The life of one unit:
at(Z)andwith_params - Accelerated Life (AL)
- Time-varying covariates across families
- Shared-frailty models
- Partial-effects plots
- Forest plots
- Penalised regression: ridge, lasso and elastic net
- Firth’s penalty: Cox regression when a covariate separates the events
- Model Selection
- Validating a survival predictor
- Saving and loading a fitted model
- Distributional Regression
- Mixture-Cure Regression
- Equivalent Time Scales
- Zero-Inflated Regression
- Interval-Censored Cox Regression
- Pseudo-Observations
- Adjusted Survival Curves
- Relative Survival
- Model Diagnostics
- Verdicts
- Cox proportional hazards
- Choosing what to check
- Adding a family
- API
- Parametric proportional hazards and accelerated failure time
- Distributional regression
- Proportional odds and additive hazards
- Aalen’s additive hazards model
- Accelerated life (life-stress) models
- Recurrent events
- Competing risks
- Univariate distributions
- Bayesian fits
- Calibration of predicted survival
- Shared frailty
- Example Applications
- Competing Risks SurPyval Modelling
- Multi-State Models
- What a multi-state model is
- When to use one
- How the data are laid out
- From a SurpyvalData
- How the estimate works, in words
- A worked example: progression of MGUS
- Covariates: a Cox model for each transition
- Parametric models: a distribution for each transition
- States seen only at visits (panel data)
- How it was checked
- What is not here yet
- References
- API
- Recurrent Event Modelling with SurPyval
- Recurrent Event Regression Modelling with SurPyval
- Intervention Analysis with SurPyval
- Software Reliability Growth
- What the models assume
- Fitting failure times
- Fitting weekly counts
- Which model?
- Which model predicts best?
- How many faults are left?
- How reliable is it now?
- How much more testing?
- When to release
- A whole number of faults: Jelinski-Moranda
- Before testing starts: defects by phase
- When a fix may not help: Littlewood-Verrall
- When the testing was not steady: effort and change points
- When not to trust the answers
- References
- Degradation Modelling with SurPyval
- Multivariate Modelling with SurPyval
- Test Planning with SurPyval
- PyMC with SurPyval
- Torch with SurPyval
SurPyval
- API
- v0.28 (14 November 2026)
- v0.27 (13 November 2026)
- v0.26 (31 October 2026)
- v0.25 (17 October 2026)
- v0.24 (9 October 2026)
- v0.23 (4 October 2026)
- v0.22 (3 October 2026)
- v0.21.0 (28 September 2026)
- v0.20.0 (23 September 2026)
- v0.19.0 (4 August 2026)
- v0.18.0 (2 August 2026)
- v0.17.0 (1 August 2026)
- v0.16.0 (22 Jul 2026)
- v0.15.2 (20 Jul 2026)
- v0.15.1 (20 Jul 2026)
- v0.15.0 (20 Jul 2026)
- v0.14.0 (19 Jul 2026)
- v0.13.0 (18 Jul 2026)
- v0.12.0 (15 Jul 2026)
- v0.10.1.0 (25 Mar 2022)
- v0.10.0.1 (22 Nov 2021)
- v0.10.0 (9 Aug 2021)
- v0.9.0 (5 Aug 2021)
- v0.8.0 (27 July 2021)
- v0.7.0 (19 July 2021)
- Deprecation Policy