如何计算平均生存时间

How to compute the mean survival time

我正在使用 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) 编辑的对象 return 来提取平均生存时间,但事实证明 print.survfit 没有不是 return 列表对象,只是 return 发送到控制台的文本。

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

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

您会看到函数 return 是一个列表,其中第一个元素是一个具有多个命名值的矩阵,包括均值和均值的标准误差。因此,例如,要提取平均生存时间,您可以这样做:

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.

使用尾部公式(因为我们的变量是非负的)你可以计算平均值作为 1-CDF 从 0 到无穷大的积分,它等于生存函数的积分。

如果我们用非参数 KM 估计替换参数生存曲线,则生存曲线只会延伸到我们数据集中的最后一个时间点。从那里开始,它“假设”该线继续笔直。因此,我们只能以“受限”方式使用尾部公式,直到我们可以定义的某个 cut-off 点(默认为我们数据集中的最后一个时间点)。

您可以使用打印函数或手动计算:

print(km, print.rmean=TRUE) # print function
sum(diff(c(0,km$time))*c(1,km$surv[1:(length(km$surv)-1)])) # manually

我在时间向量的开头添加了 0,在生存向量的开头添加了 1,因为它们不包括在内。我只将生存向量带到最后一点,因为那是最后一块。这基本上计算了 area-under 到数据中最后一个时间点的生存曲线。

如果您在最后一个点之后设置一个手动 cut-off 点,它会简单地添加该区域;例如,这里:

print(km, print.rmean=TRUE, rmean=4) # gives out 1.247
print(km, print.rmean=TRUE, rmean=4+2) # gives out 1.560
1.247+2*min(km$surv) # gives out 1.560

如果 cut-off 值低于最后一个值,它将只计算到该点的 area-under KM 曲线。

不需要使用“隐藏”survival:::survmean(km, rmean=60)

仅使用 summary(km)$table[,5:6],它会为您提供 RMST 及其 SE。 CI 可以使用正态分布的适当分位数来计算。