KM with CI ribbon does not show correctly with plotnine
Nobody has claimed this yet.
- 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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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