O'Reilly logo

R in a Nutshell, 2nd Edition by Joseph Adler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required