The goal is to assess how the use of 3 drugs affects the risk of an event.
We are using real-life observational data and as such the medications may change during the follow-up time. I am looking for some statistical technique to handle these changes and account for initiation of a drug and stopping another or using some at the same time etc.
I have thought about several approaches and using these medications as a time dependent covariate in a cox regression seems reasonable to me.
The way I am thinking about it is to have multiple rows per patient where each row represents a period where there is no change in the covariates.
I have tried to simulate some data in R :
library(survival)
library(dplyr)
library(ggplot2)
set.seed(123)
n <- 500
patient_data <- data.frame(
PatientID = rep(1:n, each = 5),
Age = sample(40:80, n, replace = TRUE),
Sex = sample(0:1, n, replace = TRUE),
Time = rep(0, n * 5),
drugA = sample(0:1, n * 5, replace = TRUE),
drugB = sample(0:1, n * 5, replace = TRUE),
drugC = sample(0:1, n * 5, replace = TRUE),
Event = rep(0, n * 5)
)
for (i in 1:n) {
follow_up_time <- sample(1:10, 5, replace = TRUE)
patient_data$Time[(i - 1) * 5 + 1:(length(follow_up_time))] <- cumsum(follow_up_time)
patient_data$Event[(i - 1) * 5 + 1:(length(follow_up_time))] <- rbinom(length(follow_up_time), 1, pmin(0.1 * follow_up_time, 0.5))
}
surv_object <- with(patient_data, Surv(Time, Event))
cox_model <- coxph(surv_object ~ Age + Sex + drugA + drugB + drugC + cluster(PatientID) , data = patient_data, id = PatientID)
summary(cox_model)
Additionally, in the simulated data I have also included multiple events per patient as the event is stroke and it could be recurrent.
Is this a valid approach?
Is there something obvious I am not thinking about?
I am not an expert in statistics in any way so I am just trying to figure this out.
Any plotting suggestions for these covariates?
Any other suggestion of other methods (even if they are complex) is welcomed.
P.S I am thinking of adding competing risk of death later on and I was also wondering if it is possible.