class: center, middle, inverse, title-slide .title[ # Time-varying covariates ] .author[ ### Yue Jiang ] .date[ ### STA 490/690 ] --- ### Why is Miss Cleo in a survival analysis lecture? <img src="img/cleo.png" width="70%" style="display: block; margin: auto;" /> -- .center[ .vocab[No one can look into the future]. ] -- .center[ .small[btw don't call that number or visit that site.] ] --- ### Re-arrest Today, we'll continue the analysis of the Rossi et al. data, examining time to re-arrest among a cohort of prisoners released from jail. As a reminder from last time, ```r head(dat) ``` ``` ## id week arrest age mar prio emp_time ## 1 1 20 1 27 not married 3 NA ## 2 2 52 0 40 not married 2 5 ## 3 3 37 1 17 not married 5 28 ## 4 4 52 0 37 not married 2 19 ## 5 5 25 1 20 not married 3 15 ## 6 6 46 1 22 not married 2 2 ``` --- ### Counting process format .question[ Third time's the charm on this question...how might we use the time-varying covariate of week of first post-release employment? I've offered a small hint in the title of this question (but don't go about searching online yet!). Think again to the contribution to the partial likelihood of each individual at each time in the Cox proportional hazards model. ] --- ### Time-varying covariates We want to get from here... ```r head(dat) ``` ``` ## id week arrest age mar prio emp_time ## 1 1 20 1 27 not married 3 NA ## 2 2 52 0 40 not married 2 5 ## 3 3 37 1 17 not married 5 28 ## 4 4 52 0 37 not married 2 19 ## 5 5 25 1 20 not married 3 15 ## 6 6 46 1 22 not married 2 2 ``` --- ### To here: ``` ## id week arrest age mar prio emp_time tstart tstop emp ## 1 1 20 1 27 not married 3 NA 0 20 0 ## 2 2 52 0 40 not married 2 5 0 5 0 ## 3 2 52 0 40 not married 2 5 5 52 1 ## 4 3 37 0 17 not married 5 28 0 28 0 ## 5 3 37 1 17 not married 5 28 28 37 1 ## 6 4 52 0 37 not married 2 19 0 19 0 ``` --- ### Time-varying covariates ```r dat3 <- tmerge(dat, dat, id = id, tstop = week) head(dat3) ``` ``` ## id week arrest age mar prio emp_time tstart tstop ## 1 1 20 1 27 not married 3 NA 0 20 ## 2 2 52 0 40 not married 2 5 0 52 ## 3 3 37 1 17 not married 5 28 0 37 ## 4 4 52 0 37 not married 2 19 0 52 ## 5 5 25 1 20 not married 3 15 0 25 ## 6 6 46 1 22 not married 2 2 0 46 ``` --- ### Time-varying covariates ```r dat3 <- tmerge(dat3, dat3, id = id, arrest = event(week, arrest)) head(dat3) ``` ``` ## id week arrest age mar prio emp_time tstart tstop ## 1 1 20 1 27 not married 3 NA 0 20 ## 2 2 52 0 40 not married 2 5 0 52 ## 3 3 37 1 17 not married 5 28 0 37 ## 4 4 52 0 37 not married 2 19 0 52 ## 5 5 25 1 20 not married 3 15 0 25 ## 6 6 46 1 22 not married 2 2 0 46 ``` --- ### Time-varying covariates ```r dat3 <- tmerge(dat3, dat3, id = id, emp = tdc(emp_time)) head(dat3) ``` ``` ## id week arrest age mar prio emp_time tstart tstop emp ## 1 1 20 1 27 not married 3 NA 0 20 0 ## 2 2 52 0 40 not married 2 5 0 5 0 ## 3 2 52 0 40 not married 2 5 5 52 1 ## 4 3 37 0 17 not married 5 28 0 28 0 ## 5 3 37 1 17 not married 5 28 28 37 1 ## 6 4 52 0 37 not married 2 19 0 19 0 ``` --- ### Time-varying covariates ```r m3 <- coxph(Surv(tstart, tstop, arrest) ~ emp + age + mar + prio, data = dat3) summary(m3) ``` ``` ## Call: ## coxph(formula = Surv(tstart, tstop, arrest) ~ emp + age + mar + ## prio, data = dat3) ## ## n= 462, number of events= 65 ## ## coef exp(coef) se(coef) z Pr(>|z|) ## emp -0.36736 0.69256 0.28860 -1.273 0.20306 ## age -0.09754 0.90707 0.03087 -3.159 0.00158 ** ## marnot married 0.90003 2.45967 0.59979 1.501 0.13347 ## prio 0.11152 1.11797 0.03510 3.177 0.00149 ** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## exp(coef) exp(-coef) lower .95 upper .95 ## emp 0.6926 1.4439 0.3934 1.2193 ## age 0.9071 1.1025 0.8538 0.9636 ## marnot married 2.4597 0.4066 0.7592 7.9693 ## prio 1.1180 0.8945 1.0437 1.1976 ## ## Concordance= 0.684 (se = 0.033 ) ## Likelihood ratio test= 30.65 on 4 df, p=4e-06 ## Wald test = 26.46 on 4 df, p=3e-05 ## Score (logrank) test = 28.26 on 4 df, p=1e-05 ``` --- ### Time-varying covariates .question[ Notice anything weird in the output on the previous slide? ] .question[ What about the fact that our "observations" are now correlated? Is a concern? ] --- ### Delaying `tdc` calls and reverse causality .question[ Think about a model where we are examining time-to-death in the hospital setting, and as a time-varying covariate we have a binary indicator for "presence of family for them to say goodbye." What do you think of this situation? What might you expect the covariate associated with that value to be? ]