CamDavidsonPilon / lifelines

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

x% confidence interval? #1608

Closed miretchin closed 6 months ago

miretchin commented 7 months ago

Hello,

Great library. Just curious if it's possible to change the % interval of the confidence interval? It defaults to 95%, but sometimes it is advantageous to change from 95% to, say, 68%.

Thank you!

dcstang commented 6 months ago

Hey @miretchin , you can use the alpha parameter - by default it is set to 0.05 for the confidence intervals.

For example in the kaplan meier fitter:

from lifelines import KaplanMeierFitter
from lifelines.datasets import load_waltons
waltons = load_waltons()

kmf = KaplanMeierFitter(label="waltons_data", alpha=0.32)
kmf.fit(waltons['T'], waltons['E'])
kmf.plot()

As per the documentation, you can pass in the alpha value on the fit method as well - and this will override the one set on the initialization of the kmf object for the current call of fit. For example, this will set it to the 68% in your question:

from lifelines import KaplanMeierFitter
from lifelines.datasets import load_waltons
waltons = load_waltons()

kmf = KaplanMeierFitter(label="waltons_data")
kmf.fit(waltons['T'], waltons['E'], alpha=0.32)
kmf.plot()
miretchin commented 6 months ago

Fantastic, thank you.