使用 R 的 predict.survreg 的 Weibull 比例风险模型的预期生存时间

机器算法验证 r 生存 冒险 威布尔分布 比例风险
2022-03-16 08:06:40

来自 R 的 Weibull 比例风险模型的预测predict.survreg()不是预期的生存时间。请帮助我理解这种行为。

对于时间,威布尔密度在 的参数化中由下式给出tdweibull()

t(ab)(tb)a1exp((tb)a)

具有形状和比例它的期望是对于具有比例的 Weibull 比例风险模型,其中是协变量和系数,密度为abbΓ(1+1a)exp(xC)xC

texp(xC)(ab)(tb)a1exp(exp(xC)(tb)a)

这可以被认为是另一个具有形状和尺度的 Weibull 密度。因此,它的期望是我希望输出这个值,但是省略了 gamma 函数的乘法。abexp(xC)1abexp(xC)1aΓ(1+1a)predict.survreg()

最小工作示例:

require(survival)
require(data.table)

dt <- data.table("covariate" = c(1,2,3), "time" = c(3,5,6))
Weibull <- survreg(Surv(dt$time) ~ dt$covariate, dist = "weibull")

a <- 1 / Weibull$scale # Transform survreg() scale to dweibull() shape.
b <- exp(Weibull$coefficients[1]) # Transform survreg() intercept to dweibull() scale.
C <- - Weibull$coefficients[2] / Weibull$scale # Transform survreg() coefficients (accelerated failure time) to proportional hazard coefficients.

# This is the expectation of the Weibull proportional hazards density.
b * exp(- dt$covariate * C / a) * gamma(1 + 1/a)
# [1] 3.171904 4.485750 6.343808

# This is what predict.survreg() outputs, verified in the predict.survreg() method.
# Notice there is no gamma() function.
b * exp(- dt$covariate * C / a)
# [1] 3.301424 4.668919 6.602849

# This the predict.survreg() call, which indeed returns the same values.
as.numeric(predict(Weibull, data.table(dt$covariate)))
# [1] 3.301424 4.668919 6.602849

我很困惑,因为对生存时间的明智预测将是它的期望,这需要伽马函数。我错过了什么?

1个回答

您的问题与这个问题有些相关,尤其是这个问题以及 Therneau, Terry M. 的以下回答。

  1. survreg 例程假设 log(y) ~ covariates + error。对于对数正态分布,误差是高斯分布,因此 predict(fit, type='response') 将是 exp(对数时间的预测平均值),而不是预测的平均时间。对于 Weibull 来说,误差分布是不对称的,所以事情变得更加混乱。每个都是该主题的 MLE 预测,只是不能解释为平均值。要获得实际平均值,您需要在教科书中查找 Weibull 和/或对数正态的公式,并将 survreg 参数化映射到教科书使用的任何一个。这两个参数化永远不会相同。

因此,您似乎不应该期望predict.survreg. Göran Broström 虽然确实提出了与您相同的观点

不需要“数学统计文本”:在 Weibull 分布的帮助页面上可以找到必要的信息:E(T) = b Gamma(1 + 1/a),其中“b”是比例(真的!)和'a' 是形状。但是,您必须考虑“survreg”使用的特殊参数化;请参阅其帮助页面了解如何操作。

上述内容确实让人有点奇怪推断其中的?predict.survreg含义

type预测值的类型。这可以是数据(响应)的原始规模,...

你的例子

相关代码是

> # look at predict function
> pred_func <- asNamespace("survival")$predict.survreg
> body(pred_func)[23]
(if (type == "lp" || type == "response") {
    if (missing(newdata)) {
        pred <- object$linear.predictors
    }
    else pred <- drop(x %*% coef) + offset
    if (se.fit) 
        se <- sqrt(diag(x %*% vv %*% t(x)))
    if (type == "response") {
        pred <- itrans(pred)
        if (se.fit) 
            se <- se/dtrans(pred)
    }
} else ...
> 
> # this is the function that is used
> dd <- survreg.distributions[["weibull"]]
> dd$itrans
function (x) 
exp(x)
<bytecode: 0x000000001e07ef00>
<environment: namespace:survival>