has2k1 / has2k1/plotnine

KM with CI ribbon does not show correctly with plotnine

Open
#1,006 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Question
Dominant language
Python
Stars
4.8k
Forks
254
Avg merge
10h 35m
Merged PRs (30d)
9

Description

Using default code

from lifelines.datasets import load_dd
data = load_dd()
kmf = KaplanMeierFitter()
kmf.fit(data["duration"], event_observed=data["observed"])
kmf.plot_survival_function()
plt.xlim(0, 20)
plt.show()

produces KM curve with CI ribbon as expected, attached.
However, combined with the following this plotnine code

km_df = kmf.survival_function_.reset_index()
km_df.columns = ["Time", "Survival"]

ci_df = kmf.confidence_interval_.reset_index()
ci_df.columns = ["Time", "Lower", "Upper"]
km_merged = km_df.merge(ci_df, on="Time")

(
p9.ggplot(km_merged, p9.aes(x="Time", y="Survival")) +
p9.geom_step(size=1.2, color="blue") +
p9.geom_ribbon(p9.aes(ymin="Lower", ymax="Upper"), alpha=0.25, fill="blue")
)

the CI ribbon is not computed/aligned correctly with the survival function, see attached.
Any idea what is going wrong?

Image Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example using the merged survival and confidence-interval data, then inspect the behavior of p9.geom_step and p9.geom_ribbon together. Compare the rendered ribbon with the lifelines plot and determine whether the issue is in the supplied data alignment or plotnine rendering; done means the confidence interval follows the survival curve correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.