rsurvival-analysishazard

What to deal with time-dependent variables in cox proportional hazard model in r


I have a question about the time-dependent variables in cox model. Supposed that I have three phases and the event may happen in any time and how can I fit these three time-dependent variables, tr1, tr2, tr3, in cox model? The sample dataset is shown below:

tr1 <- c(11.6, 19.04, NA, NA, 10.39, 4.63)
tr2 <- c(63.85, 20.29, NA, NA, 11.64, 7.33)
tr3 <- c(66.51, 22.95, NA, NA, 16.05, 9.11)


if_event <- c(1, 1, 0, 0, 1, 1)
sur_time <- c(125.81, 30.23, 59.27, 161.17, 51.36, 7.52)
income <- c(103844, 57246, 83056, 38380, 37518, 900)
population <- c(10000, 20000, 40000, 88000, 90000, 102034)
dat <- cbind(tr1, tr2, tr3, if_event, sur_time, income, population)

Can I use coxph(Surv(time, event) ~ tr1 * tr2 + tr1 * tr3 + tr2 * tr3, data) to show that time-dependent variables, tr1, tr2 and tr3?

Thanks so much for your kind help.

enter image description here

More details about the dataset:

tr1, tr2 and tr3 are three time-dependent variables since they have the same starting point, that is, tr1 means the time is from 0 to tr1 time, tr2 means the time from 0 to tr2, tr3 means the time from 0 to tr3. When if_event is 1, it shows that the event has happened and look at the record 1, the survival happened after tr3 time; for record 6, the survival happened between tr2 and tr3.


Solution

  • I'm still not sure I understand you, but I need more space to write.

    I think what you mean, is that there are 4 phases. Every individual starts in phase 1, then at time tr1 they move to phase 2, at time tr2 they move to phase 3, and at time tr3 they move to phase 4. Below I create that dataset in start-stop format, as described here. https://cran.r-project.org/web/packages/survival/vignettes/timedep.pdf

    library(survival)
    dat0 <- data.frame(
      id = 1:6,
      time = c(125.81, 30.23, 59.27, 161.17, 51.36, 7.52),
      status = c(1,1,0,0,1,1))
    dat1 <- data.frame(
      id = 1:6,
      time = rep(0, 6),
      phase = factor(c("phase1", "phase1", NA, NA, "phase1", "phase1")))
    dat2 <- data.frame(
      id = rep(1:6),
      time = c(11.6, 19.04, NA, NA, 10.39, 4.63),
      phase = factor(rep("phase2", 6)))
    dat3 <- data.frame(
      id = rep(1:6),
      time = c(63.85, 20.29, NA, NA, 11.64, 7.33),
      phase = rep("phase3", 6))
    dat4 <- data.frame(
      id = rep(1:6),
      time = c(66.51, 22.95, NA, NA, 16.05, 9.11),
      phase = rep("phase4", 6))
    dat_rbind <- rbind(dat1, dat2, dat3, dat4)
    newdat <- tmerge(dat0, dat0, id = id, status = event(time, status))
    newdat$time <- NULL
    dat <- tmerge(newdat, dat_rbind, id = id, phase = tdc(time, phase))
    dat
    #>    id status tstart  tstop  phase
    #> 1   1      0   0.00  11.60 phase1
    #> 2   1      0  11.60  63.85 phase2
    #> 3   1      0  63.85  66.51 phase3
    #> 4   1      1  66.51 125.81 phase4
    #> 5   2      0   0.00  19.04 phase1
    #> 6   2      0  19.04  20.29 phase2
    #> 7   2      0  20.29  22.95 phase3
    #> 8   2      1  22.95  30.23 phase4
    #> 9   3      0   0.00  59.27   <NA>
    #> 10  4      0   0.00 161.17   <NA>
    #> 11  5      0   0.00  10.39 phase1
    #> 12  5      0  10.39  11.64 phase2
    #> 13  5      0  11.64  16.05 phase3
    #> 14  5      1  16.05  51.36 phase4
    #> 15  6      0   0.00   4.63 phase1
    #> 16  6      0   4.63   7.33 phase2
    #> 17  6      1   7.33   7.52 phase3
    

    To interpret the data, individual 1 starts in phase 1 at time 0. For 0-11.60 they are in phase 1. At tr1 they have not yet had an event and they move from phase 1 into the next, into phase 2 from 11.60-63.85. Still no event as they move into phase 3 and phase 4. Then at time 125.81 they have an event while they were in phase 4.

    For individual 6, they experience an event at time 7.52, while they were in phase 3. This stops any future observations from happening for them, so individual 6 never enters phase 4.

    This is like I said in an earlier comment, and you said it wasn't quite right. Can you describe what the problem with this is?