CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.32k stars 551 forks source link

Is there Hazard Function in lifelines ? #1506

Closed DaniBre99 closed 1 year ago

DaniBre99 commented 1 year ago

Hi! Is possible to implement Hazard Function in python with lifelines like in R and SAS languages? Thanks

CamDavidsonPilon commented 1 year ago

Hi @DaniBre99, like you want to implement your own hazard function? Something like this?

DaniBre99 commented 1 year ago

Hi @CamDavidsonPilon! Thanks a lot for the answer! I'm doing a survival analysis with KaplanMeierFitter (lifelines) and I'd like to add a graph like this: https://bookdown.org/rwnahhas/RMPH/survival-hazard.html Or like this: https://stats.oarc.ucla.edu/sas/seminars/sas-survival/ immagine (chapter: 1.2.4. Background: The hazard function) In python I can manually calculate the hazard ratio like this: https://allendowney.github.io/SurvivalAnalysisPython/02_kaplan_meier.html (chapter: Estimating the hazard function) I was wondering if these calculations to find the hazard ratio were already included in the lifelines library or if it was possible to insert them and then create the graph. I saw the link you kindly sent me, maybe are they the same in the ThreeParamInverseTimeHazardFitter() function? I don't understand very well how this function works. Thank you very much!

CamDavidsonPilon commented 1 year ago

I see. So the Kaplan Meier Fitter would be the wrong tool, since it's purpose is to estimate the survival curve. I would suggest using the Nelson-Aalen model to get hazard rates. See these two sections: https://lifelines.readthedocs.io/en/latest/Survival%20analysis%20with%20lifelines.html#estimating-hazard-rates-using-nelson-aalen

and specifically: https://lifelines.readthedocs.io/en/latest/Survival%20analysis%20with%20lifelines.html#smoothing-the-hazard-function

DaniBre99 commented 1 year ago

Thank you very much!!