The predictions for a Weibull proportional hazards model from R's predict.survreg()
are not the expected survival times. Please help me understand this behaviour.
For time $t$, the Weibull density is given, in the parameterisation of dweibull()
, by
$t\mapsto \left(\frac{a}{b}\right) \left(\frac{t}{b}\right)^{a-1} \exp\left(-\left(\frac{t}{b}\right)^a\right)$
with shape $a$ and scale $b$. Its expectation is $b \Gamma(1 + \frac{1}{a})$. For the Weibull proportional hazards model with proportions $\exp(x^\top C)$, where $x$ are covariates and $C$ coefficients, the density is
$t \mapsto \exp(x^\top C)\left(\frac{a}{b}\right) \left(\frac{t}{b}\right)^{a-1} \exp\left(-\exp(x^\top C)\left(\frac{t}{b}\right)^a\right)$
which may be recognised as another Weibull density with shape $a$ and scale $b \exp(-x^\top C)^\frac{1}{a}$. As such, its expectation is $b \exp(-x^\top C)^\frac{1}{a} \Gamma(1 + \frac{1}{a})$. I expected predict.survreg()
to output this value, but the multiplication by the gamma function is omitted.
Minimum working example:
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
I am confused, because the sensible prediction for survival time would be its expectation, which requires the gamma function. What am I missing?