Skip to main content
3 of 9
added 33 characters in body
geek45
  • 171
  • 7

CoxPH with one ID contributing many comparator observations

I have data where one ID can serve as a comparator several times.
This is done taking into account different points in time (Variable GROUP classifies comparable observations based on the variable TIME_POINT).
ID 1 is a comparator as it is untreated (TREAT == 0).
ID 2, 3, 4, 5 and 6 are different from each other and were treated (TREAT == 1).

ID 1 therefore has different points in time to serve as a comparator for ID 2, 3, 4, 5 and 6.
ID 1 has an event. Accordingly, the duration of the follow-up time (Variable FOLLOW_UP_TIME) naturally shortens as time progresses, but of course this ID only experiences one EVENT in total.

Data: The covariates of the listed IDs were previously balanced and therefore no longer needed to be included in the cox model.

data <- data.frame(
  ID = c(1, 1, 1, 1, 1, 2, 3, 4, 5, 6),
  TREAT = c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),
  GROUP = c(5, 4, 3, 2, 1, 1, 2, 3, 4, 5),
  TIME_POINT = as.Date(c("2021-01-01", "2021-02-01", "2021-03-01", "2021-04-01", "2021-05-01", "2021-05-01", "2021-04-01", "2021-03-01", "2021-02-01", "2021-01-01")),
  EVENT_DATE = as.Date(c("2022-01-01", "2022-01-01", "2022-01-01", "2022-01-01", "2022-01-01", "2022-01-03", "2021-10-03", "0", "0", "0")),
  END_DATE = as.Date(c("2022-01-01", "2022-01-01", "2022-01-01", "2022-01-01", "2022-01-01", "2022-01-03", "2021-12-03", "2021-10-04", "2021-09-03", "2021-11-02")),
  EVENT = c(1, 1, 1, 1, 1, 1, 1, 0, 0, 0),
  FOLLOW_UP_TIME = c(365, 334, 306, 275, 245, 247, 246, 216, 214, 305)
)
ID TREAT GROUP TIME_POINT EVENT_DATE   END_DATE EVENT FOLLOW_UP_TIME
1     0     5 2021-01-01 2022-01-01 2022-01-01     1            365
1     0     4 2021-02-01 2022-01-01 2022-01-01     1            334
1     0     3 2021-03-01 2022-01-01 2022-01-01     1            306
1     0     2 2021-04-01 2022-01-01 2022-01-01     1            275
1     0     1 2021-05-01 2022-01-01 2022-01-01     1            245
2     1     1 2021-05-01 2022-01-03 2022-01-03     1            247
3     1     2 2021-04-01 2021-10-03 2021-12-03     1            246
4     1     3 2021-03-01       <NA> 2021-10-04     0            216
5     1     4 2021-02-01       <NA> 2021-09-03     0            214
6     1     5 2021-01-01       <NA> 2021-11-02     0            305

Example of GROUP == 5:

ID TREAT GROUP TIME_POINT EVENT_DATE   END_DATE EVENT FOLLOW_UP_TIME
1     0     5 2021-01-01 2022-01-01 2022-01-01     1            365
6     1     5 2021-01-01       <NA> 2021-11-02     0            305

Since an ID can occur several times as a comparator, I use bootstrapped standard errors for the cox model and tried to specify the cluster argument to account for the different time points of comparability, specified in variable GROUP:

library(survival)
library(boot)

r <- 1000

cox_fit <- function(data, indices) {
  subset_data <- data[indices, ]
  cox_model <- coxph(Surv(FOLLOW_UP_TIME, EVENT) ~ TREAT, data = subset_data, robust = TRUE, cluster = GROUP)
  return(coef(cox_model))
}

set.seed(123)
bootstrap_results <- boot(data = data, statistic = cox_fit, R = r)
print(bootstrap_results, digits = 2)

conf_level <- 0.95
boot_ci <- boot.ci(bootstrap_results, type = c("bca"), conf = conf_level)
boot_ci

Model:

ph <- coxph(Surv(FOLLOW_UP_TIME, EVENT) ~ TREAT, data = data, robust = TRUE, cluster = GROUP)

> ph
Call:
coxph(formula = Surv(FOLLOW_UP_TIME, EVENT) ~ TREAT, data = data, 
    robust = TRUE, cluster = GROUP)

        coef exp(coef) se(coef) robust se     z     p
TREAT 0.6992    2.0122   1.0223    0.7595 0.921 0.357

Likelihood ratio test=0.46  on 1 df, p=0.4975
n= 10, number of events= 7

Is the cluster argument sufficient? How to handle such situation where one contributes many times as a comparator since the model assumes 7 events?

geek45
  • 171
  • 7