question-mark
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.

Cumulative plot with show_censors option

See original GitHub issue

When I use KaplanMeierFitter.plot_cumulative_density with show_censors=True, I got AttributeError: ‘PlotEstimateConfig’ object has no attribute ‘predict_at_times’.

I modified the end of plotting.py from

        else:
            self.estimate_ = estimate
            self.confidence_interval_ = kwargs.pop("confidence_intervals")

to

        else:
            self.estimate_ = estimate
            self.confidence_interval_ = kwargs.pop("confidence_intervals")
            self.predict_at_times = cls.cumulative_density_at_times

I successfully got my cumulative plot. But I think the code should be changed more correct way.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tsjshgcommented, Jan 31, 2020

Hi Cameron, your solution fixed the error in version 0.23.9. I really appreciate your prompt response, and giving us this great library for lifetime data analysis!

0reactions
CamDavidsonPiloncommented, Jan 30, 2020

@tsjshg a better solution, and the one I’ll implement, is to change the following:

from lifelines.plotting import _plot_estimate  
       
def plot_cumulative_density(self, **kwargs):
    return _plot_estimate(
        self,
        estimate="cumulative_density_",
        **kwargs
    )

KaplanMeierFitter.plot_cumulative_density = plot_cumulative_density

So your entire script becomes:

import lifelines
from lifelines.datasets import load_canadian_senators
data = load_canadian_senators()

from lifelines.plotting import _plot_estimate  
       
def plot_cumulative_density(self, **kwargs):
    return _plot_estimate(
        self,
        estimate="cumulative_density_",
        **kwargs
    )

KaplanMeierFitter.plot_cumulative_density = plot_cumulative_density

kmf = KaplanMeierFitter()
kmf.fit(data['diff_days'], data['observed'])
kmf.plot_cumulative_density(show_censors=True)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using histograms to plot a cumulative distribution - Matplotlib
This shows how to plot a cumulative, normalized histogram as a step function in order ... A couple of other options to the...
Read more >
More examples and recipes — lifelines 0.27.4 documentation
Plotting options and styles¶ ; Standard¶ · = KaplanMeierFitter ; Show censors and edit markers¶ ·.fit ; Hide confidence intervals¶ ·.fit ; Displaying...
Read more >
cumulative distribution plots python - Stack Overflow
I am doing a project using python where I have two arrays of data. Let's call them pc and pnc. I am required...
Read more >
Plot Cumulative Distribution Function in R - GeeksforGeeks
In this article, we will discuss how to plot a cumulative distribution function (CDF) in the R programming Language.
Read more >
Creating a Cumulative Distribution Plot - SAS Help Center
The following statements use the NORMAL option to display a fitted normal distribution function on a CDF plot of breaking strengths:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

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

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found