class: center, middle, inverse, title-slide .title[ # Parametric AFT models ] .author[ ### Yue Jiang ] .date[ ### STA 490/690 ] --- ### An accelerated failure time model An .vocab[accelerated failure time] (AFT) model assumes `\begin{align*} \log(T_i) = \beta_0 + \beta_1x_{1i} + \beta_2x_{2i} + \cdots + \beta_px_{pi} + \sigma\epsilon_i \end{align*}` where `\(\epsilon_i\)` are assumed to follow some specified distribution depending on the assumed `\(f_T(t_i)\)`. (what's different here from how we defined the AFT model last time? This becomes important later) --- ### A candidate parametric AFT model ```r library(survival) aft_e <- survreg(Surv(DWHFDAYS, DWHF) ~ TRTMT + EJFPER + PREVMI, data = dig, dist = "exponential") summary(aft_e) ``` ``` ## ## Call: ## survreg(formula = Surv(DWHFDAYS, DWHF) ~ TRTMT + EJFPER + PREVMI, ## data = dig, dist = "exponential") ## Value Std. Error z p ## (Intercept) 6.62850 0.07495 88.43 < 2e-16 ## TRTMT 0.29856 0.04167 7.17 7.7e-13 ## EJFPER 0.04037 0.00239 16.92 < 2e-16 ## PREVMI -0.04978 0.04364 -1.14 0.25 ## ## Scale fixed at 1 ## ## Exponential distribution ## Loglik(model)= -20511.5 Loglik(intercept only)= -20680.3 ## Chisq= 337.51 on 3 degrees of freedom, p= 7.6e-73 ## Number of Newton-Raphson Iterations: 5 ## n= 6799 ``` --- ### The notion of a residual `\begin{align*} \log(T_i) = \beta_0 + \beta_1x_{1i} + \beta_2x_{2i} + \cdots + \beta_px_{pi} + \sigma\epsilon_i \end{align*}` .question[ What might be a sensible choice for a "residual"? What might such a residual represent? What distribution might the residual have, assuming the model is correctly specified? ] --- ### The notion of a residual `\begin{align*} \log(T_i) = \beta_0 + \beta_1x_{1i} + \beta_2x_{2i} + \cdots + \beta_px_{pi} + \sigma\epsilon_i \end{align*}` A natural suggestion might be `\begin{align*} \widehat{\epsilon}_i = \frac{\log(t_i) - \mathbf{x}_i\widehat{\boldsymbol\beta}}{\widehat{\sigma}} \end{align*}` and would have the same distribution as the `\(\epsilon_i\)` in the assumed AFT model. For instance, if `\(T_i\)` was assumed to have a lognormal distribution, `\(\epsilon_i\)` would have a normal distribution (and vice-versa). The estimated survivor function of the residuals, `\(\widehat{S}_\epsilon(\epsilon)\)`, would be from a censored sample of the true distribution `\(S_\epsilon(\epsilon)\)` if the model is correctly specified. --- ### Review: scalar change of variables Suppose `\(X\)` has pdf `\(f_X(x)\)` and let `\(Y = g(X)\)` for a strictly increasing function `\(g\)`. Then the pdf `\(f_Y(x)\)` exists, and is given by `\begin{align*} f_Y(y) = f_X\left(g^{-1}(y) \right) \Bigg|\frac{d}{dy}(g^{-1}(y))\Bigg| \end{align*}` If `\(g\)` has a non-zero continuous derivative on the support of `\(X\)`, then by the inverse function theorem, `\begin{align*} f_Y(y) &= f_X\left(g^{-1}(y) \right) \Bigg|\frac{d}{dy}(g^{-1}(y))\Bigg|\\ &= f_X\left(g^{-1}(y) \right)\big/ \Bigg|\frac{d}{dx}(g(x))\Bigg| \end{align*}` --- ### Review: scalar change of variables `\begin{align*} f_Y(y) &= f_X\left(g^{-1}(y) \right)\big/ \Bigg|\frac{d}{dx}(g(x))\Bigg| \end{align*}` .question[ Suppose `\(T\)` has some distribution `\(f_T(t)\)`, which is some valid distribution for a time-to-event outcome. What is the distribution of the transformation `\(Y = -\log S(T)\)`? ] --- ### Review: scalar change of variables `\begin{align*} y &= -\log S(t)\\ t &= S^{-1}(\exp(-y)) \end{align*}` Thus, `\begin{align*} f_Y(y) = f_T\left(S^{-1}(\exp(-y)) \right)\big/ \Bigg|\frac{d}{dt}(-\log S(t))\Bigg| \end{align*}` .question[ How else might you express `\(\frac{d}{dt}(-\log S(t))\)`? (think back to week 1) ] --- ### Review: scalar change of variables `\begin{align*} f_Y(y) &= f_T\left(S^{-1}(\exp(-y)) \right)\big/ \Bigg|\frac{d}{dt}(-\log S(t))\Bigg|\\ &= f_T\left(S^{-1}(\exp(-y)) \right)\big/ \Bigg|\frac{d}{dt}\Lambda(t)\Bigg|\\ &= f_T\left(S^{-1}(\exp(-y)) \right)\big/ \Bigg|\frac{f_T(t)}{S(t)}\Bigg|\\ &= f_T\left(S^{-1}(\exp(-y)) \right)\big/ \Bigg|\frac{f_T(S^{-1}(\exp(-y)))}{\exp(-y)}\Bigg|\\ &= \exp(-y) \end{align*}` .question[ What does this mean? ] -- For any valid time-to-event distribution `\(T\)`, `\(Y = -\log S(T)\)` has an exponential distribution with mean 1. --- ### Back to residuals Suppose the model you fit to the observed data is correctly specified. Then on the fitted data, the predicted survival time should be close to the true survival time: `\(\widehat{S}(t_i)\)` should be close to `\(S(t_i)\)`. Thus, `\(-\log \widehat{S}(t_i)\)` should behave like an exponential distribution with mean 1. .question[ How might you use this fact to evaluate whether your assumed parametric form was appropriate (Watch out for censoring)? ] --- ### Back to residuals Given right censoring (and no truncation), then the residual itself should also be right-censored: in particular, a censored sample from the `\(Exp(1)\)` distribution. In combination with the earlier fact: that the estimated survivor function of the residuals, `\(\widehat{S}_\epsilon(\epsilon)\)`, would be from a censored sample of the true distribution `\(S_\epsilon(\epsilon)\)` if the model is correctly specified, we only have to check if `\(-\log \widehat{S}_\epsilon (\widehat{\epsilon}_i)\)` has an `\(Exp(1)\)` distribution. (...we're actually not going to do this) --- ### Back to residuals ```r resids <- (log(dig$DWHFDAYS) - aft_e$linear.predictors) / 1 m1 <- survfit(Surv(resids, DWHF) ~ 1, data = dig) plot(m1, xlab = "AFT Residuals (Exponential model)", ylab = "Survival Probability") exp.x <- seq(min(resids), max(resids), length = 100) exp.y <- exp(-exp(exp.x)) # F(t) lines(exp.x, exp.y, col = "red", lwd = 2) ``` --- ### Back to residuals <!-- --> --- ### Back to residuals ```r library(survival) aft_l <- survreg(Surv(DWHFDAYS, DWHF) ~ TRTMT + EJFPER + PREVMI, data = dig, dist = "loglogistic") summary(aft_l) ``` ``` ## ## Call: ## survreg(formula = Surv(DWHFDAYS, DWHF) ~ TRTMT + EJFPER + PREVMI, ## data = dig, dist = "loglogistic") ## Value Std. Error z p ## (Intercept) 6.04825 0.11365 53.22 < 2e-16 ## TRTMT 0.48004 0.06243 7.69 1.5e-14 ## EJFPER 0.05570 0.00359 15.50 < 2e-16 ## PREVMI -0.08625 0.06517 -1.32 0.19 ## Log(scale) 0.19883 0.01835 10.84 < 2e-16 ## ## Scale= 1.22 ## ## Log logistic distribution ## Loglik(model)= -20342 Loglik(intercept only)= -20498.1 ## Chisq= 312.28 on 3 degrees of freedom, p= 2.2e-67 ## Number of Newton-Raphson Iterations: 4 ## n= 6799 ``` --- ### Back to residuals ```r resids <- (log(dig$DWHFDAYS) - aft_l$linear.predictors) / (aft_l$scale) m1 <- survfit(Surv(resids, DWHF) ~ 1, data = dig) plot(m1, xlab = "AFT Residuals (Logistic model)", ylab = "Survival Probability") exp.x <- seq(min(resids), max(resids), length = 100) exp.y <- plogis(exp.x, lower.tail = F) # F(t) lines(exp.x, exp.y, col = "red", lwd = 2) ``` --- ### Back to residuals <!-- -->