In cox regression analysis, do time dependent covariates have to persist indefinitely

I'm new to Cox regression analysis and have been following helpful advice from Therneau, Crowson and Atkinson.

I have learnt that time dependent covariates persist and that their value can be changed over time. I am dealing with a time dependent covariate that is only positive during an interval (ie. hospitalisation - where there is a specific time where this covariate starts and stops). Obviously I have entered the time of hospitalisation, but is it acceptable to enter the time the patient leaves into the model? Thus a patient's covariate for hospitalisation will be 1 for the time period of hospitalisation, and 0 before and after.

My outcome is mortality and I am looking at the effect of fever on it. Hospitalisation is entered into the model to adjust for confounding.

I am using the survival libary in R. The code for this is

df2 <- tmerge(data1 = df1, data2 = df2, id = id, hospital = tdc(hospital_start))
df2 <- tmerge(data1 = df1, data2 = df2, id = id, hospital = tdc(hospital_finish, rep(0, dim(df1)[1])))
fit.coxph <- coxph(Surv(df2$$tstart, df2$$tstop, df2\$death) ~ fever + hospital, data = df2)


Is this analysis appropriate, or should I only be entering the time of hospitalisation?

Without knowing a lot more about the purpose of your study and the nature of your data, it's hard to say what would be most appropriate. There is, however, a general principle that you can apply to make that decision for yourself, based on your understanding of the subject matter:

The covariate values used in Cox regression are those in place at the times of the events.

The Cox regression is performed event-wise, at each event time effectively comparing the current covariate values for the case having the event against the corresponding values for those still at risk but without the event.

So if you think that the effect of having been hospitalized at all affects subsequent survival with a hazard ratio independent of time, then you should include it as a covariate value for all subsequent times. If you think that the influence of prior hospitalization on outcome decreases with time so that the proportional hazards assumption is not met, then you could incorporate a model of the time dependence.

If you think that the duration of hospitalization affects subsequent survival, then you should incorporate that duration as a covariate, with similar considerations as just noted for the fact of hospitalization.

If all of your patients start hospitalized, some die during hospitalization, and some die thereafter, you should consider separate analysis of within-hospital and after-hospital survival. These might be sufficiently different situations in terms of baseline hazard and relations of covariates to survival to warrant separate analysis, with one starting at hospitalization and another at discharge. If individual patients can have multiple hospitalizations then you might need a more sophisticated analysis.

• Suppose I produce a model where my covariate is positive when a patient is in hospital, and then is negative once they leave hospital. Consider a patient who is hospitalised, then leaves hospital, then later has an event (ie. death). Is the time in hospital considered as him (a) being at risk of an event or (b) having the event? In other words, would patients who die after leaving hospital contribute to a higher or lower coefficient for my covariate of hospitalisation? Apr 26 '19 at 22:06
• @TimK if your outcome is mortality the event is death. So a patient who was hospitalized and survived while in the hospital but died after discharge was at risk during hospitalization (while there was a + covariate value) but had the event thereafter (while there was a - covariate value). Such a patient would thus tend to lower the coefficient for the hospitalization covariate: other things equal, for that patient the risk of dying was higher outside the hospital than in.
– EdM
Apr 27 '19 at 0:16