3
$\begingroup$

How do you reformat a dataset in order to perform a cox regression with time-varying covariates as a poisson regression.

I'm trying to run a survival analysis regression in python with time varying covariates. Since this functionality is still pending, I thought I'd try to exploit the link between poisson and cox. I know how to reformat the dataset in order to get identical results in the non time varying covariate case: add new observations to each individual corresponding to each death time in the dataset.

How does the following dataset need to be split? Age is a time varying covariate and event is a dummy for death occuring:

id   start   stop   event   age
 1     0      3       0      30
 1     3      5       0      33
 1     5      6       1      35
 2     0      4       1      20

As an example, the non-time varying covariate case looks as follows:

 id   start   stop   event    x
 1     0       1       1      0
 2     0       2       1      1
 3     0       3       1      0

The split dataset looks as follows:

id   start   stop   event     x   riskset
 1     0       1       1      0     0
 2     0       1       0      1     0
 3     0       1       0      0     0
 2     1       2       1      1     1
 3     1       2       0      0     1
 3     2       3       1      0     2

PHReg.from_formula("stop ~ x - 1", df, status=df['event'], ties="efron")

Gives the same results as

Poisson.from_formula("event ~ x + C(riskset) - 1", df2)

$\endgroup$
  • $\begingroup$ Which python package are you using, lifelines? $\endgroup$ – killian95 Nov 19 '18 at 19:34

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.