Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

# include median confidence interval in estimates?

See original GitHub issue

Hello,

Would it make sense to include median confidence intervals in the estimates? For example, in the object returned from `KaplanMeierFitter()`, after fitting, one could do:

``````# get the confidence interval of the median
# start by finding the median on the timeline
median_ci_idx = kmf.confidence_interval_.index.get_loc(median_lifespan,
method='nearest')
# then get the confidence interval at the point of the median
median_ci = kmf.confidence_interval_.iloc[median_ci_idx]
# to find the confidence interval for the value of the median
# we will get a horizontal line passing through the value of the
# median; note that the greater value comes earlier, and the smaller later
lcl = (kmf.survival_function_['KM_estimate']
<= median_ci.loc['KM_estimate_upper_0.95']).idxmax(0)
ucl = (kmf.survival_function_['KM_estimate']
<= median_ci.loc['KM_estimate_lower_0.95']).idxmax(0)
``````

This is what is essentially done by R, as explained in print.survfit.

### Issue Analytics

• State:
• Created 7 years ago

1reaction
robertcvcommented, Apr 6, 2021

I am sorry, now I see why it didn’t work for me. The function behaves differently depending on what you have on the input. I used `median_survival_times(kmf)` instead of `median_survival_times(kmf.confidence_interval_)` and only got the median time. I would suggest updating the documentation on this function. The parameters description uses “or” and I thought that it makes no difference if I use the model class or the confidence interval DataFrame.

0reactions
CamDavidsonPiloncommented, Apr 6, 2021

I’m not sure I’m seeing the same thing as you:

``````from lifelines.utils import median_survival_times
kmf = KaplanMeierFitter().fit(np.random.exponential(2, size=50000))
print(median_survival_times(kmf.confidence_interval_))
``````

returns two values, 1.383272 & 1.418151

#### Top Results From Across the Web

How to Find a Confidence Interval for a Median (Step-by-Step)
Step 3: Find the Confidence Interval ... The 95% confidence interval for the median will be between the j = 4 th and...
19.1 - For A Median | STAT 415
We can therefore be 93.64% confident that the population median falls in the interval (3.15, 5.35). ... In general, we should aim to...
Concept: Confidence Interval of Median
A confidence interval is usually: estimate ±1.96 * S.E.. Formula provided by KC: R = FLOOR ( ( (nobs+1) /2) - ((nobs) **0.5)/2 ......
Confidence intervals for median - Cross Validated
I have a distribution of samples with a small number of values in each one (less than 10). I have calculated the median...
Confidence interval for a median and other quantiles
In Section 4.5 we estimated medians and other quantiles directly from the frequency distribution. We can estimate confidence intervals for ...

#### Troubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free