CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.38k stars 560 forks source link

Does lifelines support hierarchical/mixed effect models? #878

Open JamesPHoughton opened 5 years ago

JamesPHoughton commented 5 years ago

Let's say that some samples are grouped (patients in a hospital, etc.) and that these groupings induce correlations between the samples.

If I'm interested in understanding the effect of treatment using a CoxPH model (or more generally a time-varying CoxPH model), is there a straightforward way for me to include a random effect for the group?

CamDavidsonPilon commented 5 years ago

Hi @JamesPHoughton The only thing I can suggest is to use the cluster_col arg (similar to the cluster in R's survival). https://lifelines.readthedocs.io/en/latest/Examples.html#correlations-between-subjects-in-a-cox-model

JamesPHoughton commented 5 years ago

Thanks! That's probably enough...

JamesPHoughton commented 5 years ago

Sorry to reopen - is there a way to pass a cluster_col to the CoxTimeVaryingFitter? I see that it's not implemented in: https://github.com/CamDavidsonPilon/lifelines/blob/master/lifelines/fitters/cox_time_varying_fitter.py#L92

Would it be an analogous operation to the implementation in https://github.com/CamDavidsonPilon/lifelines/blob/master/lifelines/fitters/coxph_fitter.py#L1208 ?

If you think the method could be ported there easily, I'd be happy to take a crack at it if you'd review for me?

CamDavidsonPilon commented 5 years ago

Hi @JamesPHoughton, it's not implemented yet, and IIRC, it's trickier than the non-time-varying model. Sorry if you lost some time here!

ioannis12 commented 3 years ago

hello,

I used the the cluster_col argument with cox regression and works pretty well, was wondering if there is a way to include a term related with the clustered_col. Something like a random intercept and a random slope

greetings

CamDavidsonPilon commented 3 years ago

@ioannis12 unfortunately not! Maybe someday