我是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)
为什么这些曲线不同?我对幸存物体的遗漏是什么?
答案 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)
看起来像