Plotting Survfit

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?

1 Answer

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.