简体   繁体   English

生存函数-R中的插值

[英]Survival function - interpolation in R

I have constructed a survival function such as: 我构造了一个生存函数,例如:

  [![plot(survfit(Surv(inf.time,infection)~1),xlab="Time (days)",ylab="Survival Probability",
                        main="Time Until Staphylococcus Infection",
                        conf.int = F)][1]][1]

在此处输入图片说明

Now i would like to determine by which time has 40% of the patients had an infection? 现在,我想确定40%的患者何时感染? How can this be written in R? 如何用R编写? Either as a command that gives me a numerical value as result or directly plotted into the survival function graph. 作为给出结果数值的命令,或者直接绘制到生存函数图中。

I am aware that the survival function depicts the probability of not having an infection, therefore i can read from the graph that survival probability of 0.6 corresponds to ca. 我知道生存函数描述了没有感染的可能性,因此我可以从图中读取到0.6的生存概率对应于ca。 45 days? 45天? How can i plot this into the graph? 如何将其绘制到图中?

i tried (with no luck): 我尝试过(没有运气):

inf.time[which(survfit(Surv(inf.time,infection)~1) == 0.6)]

I suppose, you are using survival package, right? 我想,您正在使用survival包,对吗? So you can get data frame of all points of the survival curve from "survfit" object or, easily, from "summary.survfit because it is list type under the hood. Then you can filter the df by survival probability. Some example: 因此,您可以从"survfit"对象或从"summary.survfit轻松获取生存曲线所有点的数据框,因为它是"survfit" list类型。然后您可以按生存概率过滤df。例如:

library(survival)

s <- Surv(lung$time, lung$status)

sfit <- survfit(s~1)  #get usual "survfit" object

summary_sfit = summary(sfit)

surv_df = data.frame(summary_sfit[2:6])  #somehow coerce it to data.frame

head(surv_df)

##    time n.risk n.event n.censor      surv
##  1    5    228       1        0 0.9956140
##  2   11    227       3        0 0.9824561


surv_df[max(which(surv_df$surv > 0.60)), ] 
##     time n.risk n.event n.censor      surv
##  68  245    117       1        2 0.6018576

Or you can just subset survfit$time without creating data frame 或者,您可以只将survfit$time子集survfit$time而无需创建数据框

sfit$time[max(which(sfit$surv > 0.6))]

## [1] 245

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM