# Time dependent variable in survival analysis using Cox regression

Trying to determine how to analyse a time dependent variable (rainfall) in a survival analysis. Two rows of example data for animal A and animal B as below: Each value next to the animal represents rainfall recorded (in mm) for each day, with animal A dying after day 2, and animal B surviving through past day 4.

animal A: 12, 24

animal B: 6 ,3 5, 7


If I wanted to look at the effect of TOTAL rainfall (cumulative over all days surviving), how would I code this time dependent variable WHEN the total number of days each animal survived wasn't the same. Is it even possible to analyse the effect of total rainfall when the number of days this total rainfall is calculated over differs between animals?

• (+1) The problem doesn't seem to be that the number of days varies: it is that for the survivors, you don't know the cumulative rainfall until death. Thus, total rainfall is a (right) censored variable and its censoring pattern is (strongly) related to the censoring in the outcome variable. Would this be a fair interpretation, or have I overlooked something?
– whuber
Dec 27, 2018 at 14:14
• @whuber Do you mean rainfall is a left censored value, in that we don't know how much an animal has been exposed to at time 0? If the animal dies, I don't rightly care how much rain it gets afterward: the exposure is sufficient to produce an effect. If the animal is censored after time X, then we drop them from the risk set and obtain unbiased estimates of the hazard ratio (when Cox modeling assumptions are met). Informative censoring is another issue, but I don't see that implied by the study design, unless monitors malfunction in the rain or something like that. Dec 27, 2018 at 15:12
• @AdamO I mean the opposite. When an animal is listed in the dataset as having survived to the end of the study, then we also know the cumulative rainfall to which it has been exposed during the study itself, but we do not know how much it was exposed to at the time it died. I think you ought to care about that.
– whuber
Dec 27, 2018 at 15:59
• @whuber Yes, I agree there is an issue with the coarseness of the data as presented. You will see this issue quite a bit in epidemiology. For instance, pack-years of smoking vs. CV fatality (stroke/heart attack). Say in the BRFSS linked with vital records, we may assess smoking annually, but if the respondent dies periannually, his or her smoking exposure is nondifferentially misclassified toward the null as a result of inadequate assessment. It does not kill the analysis, an informed discussion can be had about the possible biases. Dec 27, 2018 at 16:29
• I should explain further that I'm looking at survival of individuals to a certain stage of development. After a defined number of days (e.g. 10)..... the individual has survived to this stage (i.e. the minimal amount of time required to reach this stage).
– John
Dec 28, 2018 at 4:41

Cumulative exposures are coded the same way as any time varying exposure in a survival model.

You censor the observation at any event time where the covariate changes, then re-enter them into the analysis at that time with the new covariate value. In this case, the cumulative. Representing your data in a long format:

Animal Rainfall Time0 Time1 Outcome
A        0     0     1       0
A       12     1     2       0
A       46     2     3       1
B        0     0     1       0
B        6     1     2       0
B        9     2     3       0
B       15     3     4       0

• Could you explain how this answers the question? This post and your comment to the question suggest there may be several different possible interpretations, making it especially important to be clear and explicit.
– whuber
Dec 27, 2018 at 16:00
• @whuber the OP is trying to model the time to event. He or she hasn't well articulated the data structure, but A experiences an event at (the latest by the start of) day 3, and B is censored after day 4. In the mean time, daily rain exposure is recorded. The model OP is after is something like coxph(Surv(Time0, Time1, Outcome) ~ Rainfall) Dec 27, 2018 at 16:27
• My apologies, I didn't have the example data in a format appropriate before but it has since been edited. So AdamO, is it an issue that some animals have more days of rain till death than others? As in, we can assume that having more days till day is likely to automatically lead to larger cumulative values, which may bias the estimates obtained? Would it be more appropriate to only analyse the data up till the last day that all animals shared in common (e.g. only analyse cumulative rainfall up till day 3, as both animal A and B were alive for at least this amount of time).
– John
Dec 28, 2018 at 4:38
• @John Cox models only care about when you are at risk for the event. Once an animal is censored, no possible "future observation" (rain irrespective of death) could bias the analysis. Use all your information, even when duration of follow-up is imbalanced (as is the case in almost all Cox analyses). If you get 10" for one day and don't die, it tells me something. If you get 10" rain for four days and don't die, that only tells me more. The issue you are thinking about is rather one of information and power, but not bias. Dec 28, 2018 at 15:17
• Thanks for your help AdamO (and everyone else). That has answered the biggest queries I had regarding the analysis and I cant thank you enough for the help.
– John
Dec 29, 2018 at 14:23