0
$\begingroup$

I have a dataset of subjects that can fail, recover from it, and fail again. How should I put this into a CoxPHFitter and CoxTimeVaryingFitter from lifelines in Python?

I would expect that between the first and second event, the event should still be True as the subject is unreliable. Or should I only provide the first failure into the model?

$\endgroup$
1
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Commented Aug 26 at 15:17

1 Answer 1

1
$\begingroup$

The substantive issue is how you think that the repeated events might best be modeled, based on your understanding of the subject matter. The R survival vignette outlines the issues. Chapter 8 of Therneau and Grambsch goes into more detail. The following is based on your having multiple events all of the same type.

If all you care about is time to first failure, then you could just ignore all subsequent observations on an individual. As Therneau and Grambsch say (p. 169): "This is simple and easy to interpret, but there is always the concern that information is being wasted."

If you want to include information about subsequent events for an individual, then the minimum requirement is to keep track of separate individuals with some type of ID variable. That will be used to get beyond the usual assumption of independence among observations, either using a robust standard error estimate to account for intra-individual correlations to get marginal estimates or a random-effect/frailty model to get conditional estimates.

Then you have to decide on how you think about the time course of events.

One is to model the time of each event since study entry. For that you need to use the "counting process" data format, which I understand is used by CoxTimeVaryingFitter. You have a separate line for each time interval for an individual, with each interval starting at time = 0 or the time of the prior event, and ending at the next event time (noted as an event) or the last observation time without an event (right censored). This assumes mutual independence of observations within each individual. That's called the "Andersen-Gill" (AG) model.

An alternative (Therneau and Grambsch, p. 186):

is the sojourn- or gap-time scale, with intervals of $(0, t_1]$, $(0, t_2 - t_1]$, ... , corresponding to "time since entry or last event."

That wouldn't require the counting-process format but would still require keeping track of IDs.

Another possibility is to allow for different underlying hazards for each subsequent event by assigning sequential events to different strata. That can be done as a marginal or a conditional model. What Therneau and Grambsch call that the "Wei, Lin, and Weissfeld" marginal model "treats the ordered outcome data set as though it were anunordered competing risks problem." That doesn't require the counting-process data format. The "Prentice, Williams, and Peterson" conditional model "assumes that a subject cannot be at risk for event 2 until event 1 occurs" and so on.

To accomplish this, the counting process style of input is used, as in the AG model, but each event is assigned to a separate stratum. The time scale may be either time since entry or gap time.

The choice among those possibilities is yours. I'm not very familiar with the lifelines package (software-specific questions are off-topic on this site, anyway), but if it can handle multiple event types and strata then you should be able to implement whichever method you think is best.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.