简体   繁体   中英

how to do predictions from cox survival model with time varying coefficients

I have built a survival cox-model, which includes a covariate * time interaction (non-proportionality detected). I am now wondering how could I most easily get survival predictions from my model.

My model was specified:

coxph(formula = Surv(event_time_mod, event_indicator_mod) ~ Sex + 
    ageC + HHcat_alt + Main_Branch + Acute_seizure + TreatmentType_binary + 
    ICH + IVH_dummy + IVH_dummy:log(event_time_mod) 

And now I was hoping to get a prediction using survfit and providing new.data for the combination of variables I am doing the predictions:

survfit(cox, new.data=new)

Now as I have event_time_mod in the right-hand side in my model I need to specify it in the new data frame passed on to survfit . This event_time would need to be set at individual times of the predictions. Is there an easy way to specify event_time_mod to be the correct time to survfit ? Or are there any other options for achieving predictions from my model?

Of course I could create as many rows in the new data frame as there are distinct times in the predictions and setting to event_time_mod to correct values but it feels really cumbersome and I thought that there must be a better way.

You have done what is refereed to as

An obvious but incorrect approach ...

as stated in Using Time Dependent Covariates and Time Dependent Coefficients in the Cox Model vignette in version 2.41-3 of the R survival package. Instead, you should use the time-transform functionality , ie, the tt function as stated in the same vignette. The code would be something similar to the example in the vignette

> library(survival)
> vfit3 <- coxph(Surv(time, status) ~ trt + prior + karno + tt(karno),
+                data=veteran,
+                tt = function(x, t, ...) x * log(t+20))
> 
> vfit3
Call:
coxph(formula = Surv(time, status) ~ trt + prior + karno + tt(karno), 
    data = veteran, tt = function(x, t, ...) x * log(t + 20))

              coef exp(coef) se(coef)     z       p
trt        0.01648   1.01661  0.19071  0.09  0.9311
prior     -0.00932   0.99073  0.02030 -0.46  0.6462
karno     -0.12466   0.88279  0.02879 -4.33 1.5e-05
tt(karno)  0.02131   1.02154  0.00661  3.23  0.0013

Likelihood ratio test=53.8  on 4 df, p=5.7e-11
n= 137, number of events= 128 

The survfit though does not work when you have a tt term

> survfit(vfit3, veteran[1, ])
Error in survfit.coxph(vfit3, veteran[1, ]) : 
  The survfit function can not yet process coxph models with a tt term

However, you can easily get out the terms , linear predictor or mean response with predict . Further, you can create the term over time for the tt term using the answer here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM