Survival Analysis in R

Peter Dalgaard‘s Introductory Statistics with R is an accessible text full of examples to learn R. In the chapter on survival analysis (chapter 14), the book seems to have become outdated, and a small modification is needed to get the code run:

library(survival) # package for survival analysis
library(ISwR) # for the data in the example
attach(melanom)
s <- Surv(days, status==1) # creating Surv object
s.fit <- survfit(s~1) # note the ~1 formula
plot(s.fit) # Kaplan–Meier plot

According to the code in the book, the code s.fit <- survfit(s) would work; it doesn’t. We need to specify a formula even in the empty model (compare this to the univariate example on p.253).

It’s a trivial thing, but for the uninitiated R can be a bit daunting, especially when the cookbook at hand fails… and the online help isn’t consulted.

Dalgaard, Peter. 2008. Introductory Statistics with R. Springer.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s