CamDavidsonPilon / lifelines

Survival analysis in Python

Home Page:lifelines.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

x% confidence interval?

miretchin opened this issue · comments

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!

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()

Fantastic, thank you.