r - 如何计算平均生存时间

标签 r survival-analysis

我正在使用survival库。计算生存函数的 Kaplan-Meier 估计量后:

km = survfit(Surv(time, flag) ~ 1)

我知道如何计算百分位数:

quantile(km, probs = c(0.05,0.25,0.5,0.75,0.95))

但是,我如何计算平均生存时间?

最佳答案

计算平均生存时间

平均生存时间通常取决于为最大生存时间选择的值。您可以使用 print(km, print.rmean=TRUE) 获取受限的平均生存时间。默认情况下,假设最长生存时间等于数据中的最长生存时间。您可以通过添加 rmean 参数(例如 print(km, print.rmean=TRUE, rmean=250))将其设置为不同的值。

提取平均生存时间的值并存储在对象中

回应您的评论:我最初认为可以通过查看 print(km, print.rmean=TRUE) 返回的对象来提取平均生存时间,但事实证明 print.survfit 不返回列表对象,而只是将文本返回到控制台。

相反,我查看了 print.survfit 的代码(您可以通过在控制台中输入 getAnywhere(print.survfit) 来查看代码),看看在哪里计算平均生存时间。事实证明,一个名为 survmean 的函数可以处理这个问题,但它不是导出函数,这意味着当您尝试像“正常”函数一样运行它时,R 将无法识别该函数。因此,要访问该函数,您需要运行以下代码(您需要显式设置 rmean):

survival:::survmean(km, rmean=60) 

您将看到该函数返回一个列表,其中第一个元素是一个具有多个命名值的矩阵,包括平均值和平均值的标准误差。因此,要提取例如平均生存时间,您可以执行以下操作:

survival:::survmean(km, rmean=60)[[1]]["*rmean"]

有关如何计算平均生存时间的详细信息

print.survfit 的帮助提供了有关选项以及如何计算限制平均值的详细信息:

?print.survfit 

The mean and its variance are based on a truncated estimator. That is, if the last observation(s) is not a death, then the survival curve estimate does not go to zero and the mean is undefined. There are four possible approaches to resolve this, which are selected by the rmean option. The first is to set the upper limit to a constant, e.g.,rmean=365. In this case the reported mean would be the expected number of days, out of the first 365, that would be experienced by each group. This is useful if interest focuses on a fixed period. Other options are "none" (no estimate), "common" and "individual". The "common" option uses the maximum time for all curves in the object as a common upper limit for the auc calculation. For the "individual"options the mean is computed as the area under each curve, over the range from 0 to the maximum observed time for that curve. Since the end point is random, values for different curves are not comparable and the printed standard errors are an underestimate as they do not take into account this random variation. This option is provided mainly for backwards compatability, as this estimate was the default (only) one in earlier releases of the code. Note that SAS (as of version 9.3) uses the integral up to the last event time of each individual curve; we consider this the worst of the choices and do not provide an option for that calculation.

关于r - 如何计算平均生存时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43173044/

相关文章:

r - 如何使用风险表 (R) 在生存图中添加垂直线和注释

r - 实现聚类的邻近矩阵

r - 如何在远程服务器上轻松执行R命令?

r - Autoloads 环境有什么作用?

python - Pandas Dataframe 到具有多个键的字典

r - 如何叠加 contsurvplot 包中的两个 ggplot2 对象?

r - 使用重复时忽略大小写

r - R-参数方法中的预测生存曲线

r - 在 R Studio 中,当我添加截距线时,我的风险表将从我的生存图中删除。有什么办法可以克服这个问题吗?

r - MTTF 的置信区间 - R 中的威 bool 生存曲线