绘制幸存者

时间:2011-04-29 15:06:04

标签: r plot

我是R的新手,正在尝试绘制survfit生存曲线。

在玩survfit对象时,我发现我得到了两个不同的图:

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)

为什么这些曲线不同?我对幸存物体的遗漏是什么?

1 个答案:

答案 0 :(得分:7)

您缺少time变量

尝试

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)

看起来像

mysurvfit