Survival Models

Survival analysis is concerned with looking at the amount of time that elapses before an event occurs. An obvious application is to look at mortality statistics (predicting how long people live), but it can also be applied to mechanical systems (the time before a failure occurs), marketing (the amount of time before a consumer cancels an account), or other areas.

In R, there are a variety of functions in the survival library for modeling survival data.

To estimate a survival curve for censored data, you can use the survfit function:

library(survival)
survfit(formula, data, weights, subset, na.action, etype, id, ...)

This function accepts the following arguments.

ArgumentDescription
formulaDescribes the relationship between the response value and the predictors. The response value should be a Surv object.
dataThe data frame in which to evaluate formula.
weightsWeights for observations.
subsetSubset of observation to use in fitting the model.
na.actionFunction to deal with missing values.
etypeThe variable giving the type of event.
idThe variable that identifies individual subjects.
typeSpecifies the type of survival curve. Options include "kaplan-meier", "fleming-harrington", and "fh2".
errorSpecifies the type of error. Possible values are "greenwood" for the Greenwood formula or "tsiatis" for the Tsiatis formula.
conf.typeConfidence interval type. One of "none", "plain", "log" (the default), or "log-log".
conf.lowerA character string to specify modified lower limits to the curve; ...

Get R in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.