bigjim
bigjim

Reputation: 948

Plotting survfit

I'm new to R and am trying to plot survfit survival curves.

In playing around with the survfit object, I found that I get 2 different plots for the following:

library(survival)

#example survfit object
mysurvfit <- survfit(Surv(time, status)~1, data=aml)

#default survfit plot, survival curve with upper & lower conf intervals
plot(mysurvfit, mark.time=FALSE, conf.int=TRUE)

#create another curve by accessing surv, upper, lower
#(I'd expect this to produce the same as above, but it doesn't)
lines(mysurvfit$surv, col="blue",lty=1)
lines(mysurvfit$upper, col="blue",lty=2)
lines(mysurvfit$lower, col="blue",lty=2)

Why are these curves different? What am I missing about the survfit object?

Upvotes: 3

Views: 4270

Answers (1)

Henry
Henry

Reputation: 6784

You are missing the time variable

Try

plot(mysurvfit, mark.time=FALSE, conf.int=TRUE)
lines(mysurvfit$surv ~ mysurvfit$time, col="blue",lty=1)
lines(mysurvfit$upper ~ mysurvfit$time, col="blue",lty=2)
lines(mysurvfit$lower ~ mysurvfit$time, col="blue",lty=2)

which looks like

mysurvfit

Upvotes: 7

Related Questions