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.