获得一个 'survfit' 对象,如果出现平局,该对象的大小将与原始数据相同? (生存,R)

Get a 'survfit' object which will be the same size than the original data in case of ties? (survival, R)

我想要 Kaplan-Meier 估计器为我的数据帧中的每个个体估计的生存概率。 survfit(Surv(.)) 函数计算按降序排列的每个唯一时间的生存概率。

survfit 对象中获取每个个体的生存概率的优雅方法是什么?

library(survival)
data = data.frame(cbind(id = 1:10, 
            time = c(2,3,4,5,2,3,8,9,10,11), 
            status = c(1,0,0,1,0,1,0,1,0,1)))
survfit(Surv(data$time, data$status)~1)$surv
 # 0.9000 0.7875 0.7875 0.6300 0.6300 0.4200 0.4200 0.0000
survfit(Surv(data$time, data$status)~1)$time
 #  2  3  4  5  8  9 10 11

提前致谢!

您可以将结果放入 data.frame,然后将其合并回

merge(data, 
   with(survfit(Surv(data$time, data$status)~1), data.frame(time, surv))
)

这里我只是使用 with() 从 survfit 结果中轻松提取两列。