Simple question, how do you specify time dependent covariates in the data.frame supplied to newdata when looking to make predictions?
In other words, I fit a model with time dependent covariates:
cfit <- coxph(Surv(tstart, tstop, status) ~ treat + sex + age +
inherit + cluster(id), data=cgd)
Now I'd like to create a prediction for a patient, but using updated data from that patient. In other words, what is their survival probability, given that we observed changes in certain covariates within that certain time intervals?
I can predict survival for a new patient, as follows:
survfit(cfit, newdata=data.frame(treat = "placebo", age = 12, sex ="male", inherit = "X-linked"))$surv
But this does not allow me to update predictions as time passes from the start of observation for that patient, allowing for the incorporation of updated covariates.
This is detailed in the 4th paragraph of the details section of the help page ?survfit.coxph. Basically you need an id column that shows which rows belong to the same person, then for each row you need the beginning time, the ending time, and the values of the covariates during that time period. Each time period for the individual being predicted will have its own row in newdata (so the time periods should not overlap).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With