# Using the Weibull Accelerated Failure Time Regression Model to Predict Time to Health Events
## 9 An Example to Predict the Survival Time  
We use a publicly available larynx cancer dataset to illustrate the process of making survival time predictions. This dataset consists of records for 90 male larynx cancer patients, each with five variables: the stage of the disease (stage: 1, 2, 3, 4), the time to death or the duration of on-study time in months (time), the age at the diagnosis of larynx cancer (age), the year of diagnosis of larynx cancer (diagyr), and a death indicator (death: 0 = alive, 1 = dead). We added a new variable ID into the dataset and changed the variable name delta to death. The dataset can be downloaded from [[https://vincentarelbundock.github.io/Rdatasets/datasets.html](https://vincentarelbundock.github.io/Rdatasets/datasets.html)]([https://vincentarelbundock.github.io/Rdatasets/datasets.html](https://vincentarelbundock.github.io/Rdatasets/datasets.html)).  
The larynx cancer data are structured as follows:  
ID stage time age diagyr death  
1 1 0.6 77 76 1  
2 1 1.3 53 71 1  
3 1 2.4 45 71 1  
4 1 2.5 57 78 0  
5 1 3.2 58 74 1  
............  
46 2 6.2 74 72 1  
47 2 7.0 62 73 1  
48 2 7.5 50 73 0  
49 2 7.6 53 73 0  
50 2 9.3 61 71 0  
51 3 0.3 49 72 1  
52 3 0.3 71 76 1  
.........  
89 4 3.8 84 74 1  
90 4 4.3 48 76 0  
We used two predictor variables to make survival time predictions: the stage of the disease and the age at the diagnosis of larynx cancer. Since the \"stage\" is a categorical variable, we created three dummy variables for stages 2, 3, and 4, with stage 1 as the default reference group. The survival probability of patients at various stages and time intervals can be observed in the following Kaplan-Meier plot (Figure 1):The Weibull AFT model can be expressed as follows:  
\[\log(T)=\beta_{0}+\beta_{1}*stage2+\beta_{2}*stage3+\beta_{3}*stage4+\beta_{4}* age+\sigma e\quad\epsilon\sim G(0,1)\]  
Most statistical software, such as R, can be used to run the Weibull regression model. In R, we can use the following code:  
library(survival)  
larynxx<-read.csv(\"D:/larynx.csv\")  
wr <- survreg(Surv(time, death) ~ factor(stage) + age,  
data = larynxx,dist=\"w\")  
summary(wr)  
The following results were obtained from the model:  
Call:  
survreg(formula = Surv(time, death) ~ factor(stage) + age, data = larynx,  
dist = \"w\")  
Value Std. Error z p  
(Intercept) 3.5288 0.9041 3.903 9.50e-05  
factor(stage)2 -0.1477 0.4076 -0.362 7.17e-01  
factor(stage)3 -0.5866 0.3199 -1.833 6.68e-02  
factor(stage)4 -1.5441 0.3633 -4.251 2.13e-05  
age -0.0175 0.0128 -1.367 1.72e-01  
Log(scale) -0.1223 0.1225 -0.999 3.18e-01  
Scale= 0.885  
Weibull distribution  
Loglik(model)= -141.4 Loglik(intercept only)= -151.1  
Chisq= 19.37 on 4 degrees of freedom, p= 0.00066  
Number of Newton-Raphson Iterations: 5  
n= 90  
Suppose we want to predict the survival time for a patient with ID = 46, who is at larynx cancer stage 2 and is 74 years old. We can use the following equations:  
1. To calculate the mean time to failure (MTTF): \[MTTF_{46} =E(\hat{t}_{46})=\exp(\boldsymbol{x}_{i}^{\prime}\boldsymbol{ \beta})\Gamma(\sigma+1)\] \[=exp(3.5288-0.1477*1-0.5866*0-1.5441*0-0.0175*74)*\Gamma(1.885)\] \[=7.7(months)\]  
Figure 1: Kaplan–Meier plot of survival probability  
2. To calculate the median survival time: \[Median_{46} = \left(\log 2\right)^{\phi}\exp\left(x_{i}^{\prime}\hat{\beta}\right)\] \[= \log(2)^{0.885}exp\left(3.5288-0.1477*1-0.5866*0-1.5441*0-0.0175*74\right)\] \[= 5.8\text{ (months)}\]
3. To calculate the minimum prediction error survival time (MPET) using Equation (26) with a fixed \(k\) = 2: \[MPET_{46} = \left[\frac{\frac{2}{\phi}\log(k)}{k^{\frac{1}{\phi}}-k^{-\frac{1}{ \phi}}}\right]^{\sigma}\exp\left(x^{\prime}\beta\right)\] \[= \left[\frac{\frac{2}{\phi}\log(k)}{2^{\frac{1}{\phi}\log(k)}-k^{- \frac{1}{\phi}\log(k)}}\right]^{0.885}*\exp\left(3.5288-0.1477*1-0.5866*0-1.5441*0 -0.0175*74\right)\] \[= 7.4\text{ (months)}\] It seems that these prediction methods yield results quite close to the real survival time of patient ID = 46, which was 6.2 months.