# Does the Cox proportional hazards model process past values for time-varying covariates?

I am currently working on a survival analysis project and am struggling regarding the inner workings of the coxph function of the survival package in R.

The project investigates the influence of a numeric measure on employee tenure lengths. The measure is calculated for every calendar week. To do this, I am using coxph. More precisely, the version for time-varying covariates:

out <- coxph(formula = Surv(tstart, tstop, turnover) ~ score, data = mydata)


Essentially, the survival analysis should check the recent history of scores and not just the value of the current week. However, I am unsure whether this is already part of standard procedure of coxph or whether I need to adjust the score values myself (e.g. via a rolling total over the last X weeks). Unfortunately, sources seem to disagree about this aspect.

In the answer to this question, it seems past values of the time-varying covariate are automatically included.

In other words, the hazard at time t depends on the probability of the event to happen at time t, given that it has not happened so far (T≥t) and given the past (H(t_)). This past includes information up to time t.

In contrast, the authors of this vignette state the opposite:

The model tries to assign a risk score to each subject that best predicts the outcome of each drawing based on [...] The covariate values of each subject just prior to the event time.

I would be grateful for some clarification regarding this aspect of the Cox proportional hazards model in R as it determines how I need to prepare my data and interpret the output.

It seems that your question concerns not the specific R function coxph, but survival models in general. The vignette, when speaking about "covariate values of each subject just prior to the event time", refers to the hazard function $h(t)$. This function in fact only takes into account the current values of covariates, and determines the risk for individuals "alive" at day $t$ to suffer the event at day $t+1$.
However, to calculate the number of individuals that are still "alive" at $t$, you need the full history of covariates - and that is where the past values come in. One could build a model iteratively, by calculating the number of individuals for every $t$ and testing whether they survive one more day, but using the cumulative hazard function $H(t)$ makes everything much easier to process.

To give an example, consider the event "getting hit by a car", and covariate "amount of traffic today". High amount of traffic on one day means that the risk to get hit that particular day, $h(t)$, is high; also, only few individuals are likely to survive past it ($H(t)$ is high). However, given that you survived that day, the momentary risk next day $h(t+1)$ is not influenced by the past. If you specifically want to model some damage which persists after exposure, you will need to explicitly add that as a covariate.

Thought I should add a disclaimer that I am not familiar with using time-dependent covariates in that particular R function, so anyone more experienced with it is welcome to correct me.

• Ah, thank you very much. That explanation makes sense. I misunderstood the reference to the past and thought it related to the hazard function instead of the individuals at risk. I appreciate the quick response! Commented Feb 27, 2017 at 21:36

The answer from @juod gets to the essential point: calculations in Cox regressions are based on instantaneous values of covariates "just prior to" each event. Prior history is taken into account in the following way: each individual still at risk at an event time survived up until then, so those individuals' covariate values (potentially time-varying) at all earlier event times have already been incorporated into the regression.

As the answer in the Cross Validated page to which you linked states, however, you may construct the instantaneous values of the time-dependent covariates in any way that makes sense. That question was posed specifically about a cumulative covariate, integrated over time, so that its value for an indivdual at each event time depended (in that particular way) on all previous values for that individual. If some way of treating your covariate values like that makes sense for your application, then do so.

Think carefully about how you wish to proceed. Is the simple fact that an individual has survived up to a particular event time, given the individual's prior covariate values, enough of a way to incorporate history? Or do you need to add up or average or otherwise assess prior values over some period of time to find the best instantaneous relation between the covariate and outcome in Cox regression? That decision must be based on your understanding of the underlying subject matter.

• Thanks for the additional feedback. You raised a very good point there. So far, I disregarded the fact that survival of an individual implicitly contains the prior covariate history. I will have to rethink this issue. Since the focus of the analysis is on relative instantaneous hazards, I will probably stick to the current approach. Nevertheless, I will have to rephrase some aspects of the hypothesised correlation. Commented Mar 1, 2017 at 20:17