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.

Assessment

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

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.

Description

Question

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
Dominant language
Python
Stars
4.8k
Forks
269
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from has2k1/plotnine

All issues in has2k1/plotnine

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.