0
$\begingroup$

I am analyzing the time (since 2000) of a policy adoption using R. These policies can be updated and so I think a recurrent Prentice Williams Peterson (PWP) model is appropriate. The challenge is that I have time-varying covariates. I've seen a bunch of questions online with either recurrent events (example) and time varying covariates (example), but not both.

Here's some code for fake data:

id<-c(rep(1,5),rep(2,5),rep(3,5))
year<-c(rep(2000:2004,3)) 
event<-c(0,0,1,0,0,0,0,0,0,0,0,1,0,1,0)
sequence<-c(1,1,1,2,2,1,1,1,1,1,1,1,2,2,3)
seq_year<-c(1,2,3,1,2,1:5,1,2,1,2,1)
df<-data.frame(id,year,event,sequence,seq_year)
set.seed(1)
df$x<-rnorm(15)

Which gives me this:

df
    id year event sequence seq_year          x
1   1 2000     0        1        1 -0.6264538
2   1 2001     0        1        2  0.1836433
3   1 2002     1        1        3 -0.8356286
4   1 2003     0        2        1  1.5952808
5   1 2004     0        2        2  0.3295078
6   2 2000     0        1        1 -0.8204684
7   2 2001     0        1        2  0.4874291
8   2 2002     0        1        3  0.7383247
9   2 2003     0        1        4  0.5757814
10  2 2004     0        1        5 -0.3053884
11  3 2000     0        1        1  1.5117812
12  3 2001     1        1        2  0.3898432
13  3 2002     0        2        1 -0.6212406
14  3 2003     1        2        2 -2.2146999
15  3 2004     0        3        1  1.1249309

My question is whether my tstart and tstop should be relative to the year or the sequence year? They give similar but not identical results, so I'm not sure which is correct, if either is correct.

summary(coxph(Surv(year-1,year,event) ~ x + cluster(id) + strata(sequence), data=df)) ###tstart from year
summary(coxph(Surv(seq_year-1,seq_year,event)~x + cluster(id) + strata(sequence), data=df)) ###tstart from sequence

Also, would it be correct to include a sequence year variable in the first equation (or a year variable in the second)? My gut tells me yes, but I'm unsure.

Thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.