Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting survfit

Tags:

plot

r

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?

like image 424
bigjim Avatar asked Mar 09 '26 00:03

bigjim


1 Answers

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

like image 157
Henry Avatar answered Mar 10 '26 12:03

Henry