CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.34k stars 552 forks source link

kmf.fit -> is_left_censoring? #1186

Open GrowthJeff opened 3 years ago

GrowthJeff commented 3 years ago

Hey there!

In #1181 I corrected the "code" used in the left censoring example to ensure that a CDF was plotted. In this example the reader is told, "Instead of producing a survival function, left-censored data analysis is more interested in the cumulative density function."

Since survival analysis seems like magic to me, with its ability to see beyond the veil (left or right censored data), I opened up kaplan_meier_fitter.py to see what's going on. I see this line of code, which suggests to me that the original intention of kmf.plot() on left censored data was to plot a cumulative density function.

# if the user is interested in left-censorship, we return the cumulative_density_, no survival_function_,
        is_left_censoring = CensoringType.is_left_censoring(self)
        primary_estimate_name = "survival_function_" if not is_left_censoring else "cumulative_density_"
        secondary_estimate_name = "cumulative_density_" if not is_left_censoring else "survival_function_"

I'm struggling to make sense of the syntax here, but the general idea seems to be:

But that doesn't seem to be how the code operates today based on #1181.

  1. Do we want kmf.plot() to automatically do a CDF for left censored fits? I don't think so based on discussion in #1180.
  2. Is the above code doing what it's supposed to? 🤔
CamDavidsonPilon commented 3 years ago

I actually apologize - previous Cameron way over-engineered this class and made us all confused today 🙃

Anyways, I think the correct behaviour is as follows:

I may, in the future, drop plot altogether so no future user will be confused by issues like this.