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 <开发者_StackOverflow社区- 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?
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
精彩评论