In an oncology clinical trial, how to predict additional survival time for remaining patients who
have been observed for some time and still alive based on data observed up to date, taking into below considerations?
baseline characteristics of the patients who are still alive, like age and gender
the death hazard varies over time so the hazard should be piecewise for different time intervals
Hazard of censoring
do the simulation for 1000 to average the predicted additional time for those remaining patients.
Please provide example code with simulated data in R software, with step by step explanation.
Assistant
Step 1: Creating simulated data
To illustrate the procedure, we will create simulated data. Suppose we have a clinical trial with 500 patients, who are either male or female with age ranging from 40 to 80 years. We generate the data using the following code:
{r}
set.seed(123)
n <- 500
age <- round(runif(n, 40, 80))
gender <- sample(c("Male", "Female"), n, replace = TRUE)
time <- rexp(n, rate = 0.01)
status <- rbinom(n, size = 1, prob = pmin(1, 2*time/mean(time)))
Here, we set the seed to ensure replicability. We generate 500 random age values between 40 and 80. The gender is a binary variable, which we generate using the sample function. We assume that the survival time of patients follows an exponential distribution with a rate of 0.01, which yields an average survival time of 100 units. We generate the status variable, which is a binary variable indicating whether the patient has died (1) or is still alive (0).
Step 2: Creating a mutistate survival object from the simulated data
We will use the mstate and survival packages to create a multi-state survival object from the simulated data. The mstate package provides tools for analyzing multi-state models, and the survival package provides tools for survival analysis.
{r}
library(mstate)
library(survival)
msdata <- data.frame(time = time, status = status, age = age, gender = gender)
ms <- mstate::msprep(state = msdata$status, time = msdata$time,
event = 1:length(msdata$status))
y <- cbind(ms[[1]], as.numeric(msdata$gender == "Female"), msdata$age)
First, we create a data frame (msdata) with the columns time, status, age, and gender. Then, we use the msprep function to create a multi-state object (ms) from the survival data. The msprep function takes as input the survival data in the form of a time-to-event data frame (time, status) and creates a multi-state object with the corresponding states. In this case, we specify that the event is the length of the status vector.
Next, we create a matrix y with the covariates age and gender. We include a 1 for the first state, which is the state corresponding to the survival time.
Step 3: Fitting a piecewise Cox model
We will fit a piecewise Cox model to the multi-state object using the coxph function from the survival package. We will use the timefix argument to specify the breakpoints for the piecewise Cox regression as 0, 50, and 100 units.
{r}
fit <- coxph(Surv(ms$data$timefix, ms$data$trans) ~ tt(as.numeric(msdata$gender == "Female")) +
tt(msdata$age), tt = function(x, t) x*pmin(t, c(50, 100))/100,
data = ms, ties = "breslow")
summary(fit)
Here, we specify the dependent variable as the timefix and trans variables of the ms$data object, which represent the transformed time and the transition status. We use the tt function to specify the piecewise hazard function. We include the covariates gender and age in the formula, which we transform using the tt function. We set the breakpoints for the piecewise regression as 50 and 100 units for age and 0, 50, and 100 units for gender.
Step 4: Producing predicted additional survival times using the model
We will use the survfit.coxph function from the survival package to produce predicted survival curves for the remaining patients in the clinical trial. We will simulate 1000 survival curves for patients with age 50 and female gender to obtain the predicted additional survival times for the remaining patients.
First, we specify the time points at which we want to predict survival (tnew). Then, we simulate 1000 survival curves for patients with age 50 and female gender using a loop. For each time point, we create a data frame (newdata) with the covariates time, gender, age, and id. We set the state to 0 for all patients, indicating that they are still alive. Then, we create a multi-state object (pred_ms) from the data frame using the msprep function. We fit a Cox proportional hazards model to the multi-state object using the survfit.coxph function and obtain the predicted survival probabilities using the predict function. Finally, we calculate the mean predicted survival probability at each time point using the apply function and obtain the predicted additional survival times for the remaining patients.