Methods for Survival and Duration Analysis

statsmodels.duration implements several standard methods for working with censored data. These methods are most commonly used when the data consist of durations between an origin time point and the time at which some event of interest occurred. A typical example is a medical study in which the origin is the time at which a subject is diagnosed with some condition, and the event of interest is death (or disease progression, recovery, etc.).

Currently only right-censoring is handled. Right censoring occurs when we know that an event occurred after a given time t, but we do not know the exact event time.

Survival function estimation and inference

The statsmodels.api.SurvfuncRight class can be used to estimate a survival function using data that may be right censored. SurvfuncRight implements several inference procedures including confidence intervals for survival distribution quantiles, pointwise and simultaneous confidence bands for the survival function, and plotting procedures. The duration.survdiff function provides testing procedures for comparing survival distributions.

Examples

Here we create a SurvfuncRight object using data from the flchain study, which is available through the R datasets repository. We fit the survival distribution only for the female subjects.

The main features of the fitted survival distribution can be seen by calling the summary method:

sf.summary().head()

We can obtain point estimates and confidence intervals for quantiles of the survival distribution. Since only around 30% of the subjects died during this study, we can only estimate quantiles below the 0.3 probability point:

sf.quantile(0.25)
sf.quantile_ci(0.25)

To plot a single survival function, call the plot method:

sf.plot()

Since this is a large dataset with a lot of censoring, we may wish to not plot the censoring symbols:

Regression methods

Proportional hazard regression models (“Cox models”) are a regression technique for censored data. They allow variation in the time to an event to be explained in terms of covariates, similar to what is done in a linear or generalized linear regression model. These models express the covariate effects in terms of “hazard ratios”, meaning the the hazard (instantaneous event rate) is multiplied by a given factor depending on the value of the covariates.