Cox Proportional Hazard model (Time dependent covariates) in R

I'm doing a survival analysis using the cox proportional hazard model. I have time dependent covariates so In order to encode time-dependent covariates I used the (start, stop] form of the model described in the following document https://cran.r-project.org/web/packages/survival/vignettes/timedep.pdf. The subjects have different starting (time1) times and stopping times (time2) between 2000 and 2019. My data then looks something like this (but then for around 37000 observations):

I then used the following code to estimate the model and plot the survival curves.

fit <- coxph(Surv(time1, time2, findis) ~ Gearing + PE + crisis + cluster(IDNR), data=mydata)
plot <- ggadjustedcurves(fit, variable = mydata\$PE)


While the estimation output makes sense with my expectations, my problem is that when I run ggadjustedcurves it just keeps on going forever. If I try to plot the curves using: plot(fit) I get the graph below which doesn't seem right to me either, it seems like the graph might look better if it didn't start at zero but at 2000? Can someone tell me what I might be doing wrong? I hope I made everything clear this is my first time using this site.

1 Answer

Usually survival curves are plotted with time 0 for each subject (calling each of your distinct IDNR values a "subject") being the time that the particular subject entered the study. With the way you've set this up, there would be no events until time = 2000 or so (hence your plot), and a subject entering in 2015 could appear to survive longer than one who entered in 2007 just because the subject starting in 2015 entered the study later than the other one. If your data for some reason aren't compatible with time 0 as representing study entry date for each subject, then you have to deal with more difficult issues of data truncation or censoring of entry times, a more advanced topic.

So, if appropriate, define time 0 for each subject as the corresponding study entry date and then represent the subsequent (start, stop] times for that subject relative to the corresponding time 0 reference. For example, subtract 2015 from all times for the first subject you show, subtract 2007 for the second, etc.

As these seem to be yearly data covering only a short span of years, a Cox model might not be the best choice. For example there will be many apparent ties in event times, and you only know the event times with limited precision. This type of data might be better handled by discrete-time survival analysis.

• Thank you for the clarification. As you suggested I defined time 0 for each subject as the corresponding study entry date and then represent the subsequent (start, stop] times for that subject relative to the corresponding time 0 reference. When plotting the survival functions however, I now get Error in Surv(start, stop, findisZM) : Time variable is not numeric Jun 7, 2020 at 13:09
• @Oscar questions about coding per se are off topic on this site. See this page for links to help with R. This type of problem can arise when data are transformed from one type of file to another, if imported data are interpreted for some reason as character strings instead of numbers. Usually something like: mydata[,c("time1","time2")] <- as.numeric(mydata[,c("time1","time2")]) will fix the problem or help point you to the data values that really aren't numeric.
– EdM
Jun 7, 2020 at 14:38
• Thank you for your help, I figured it out! Using as.numeric() indeed fixed it. Jun 7, 2020 at 14:59