From 2abf0dde8e1363e28f07ff4570eac5bdb5de99b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Jolivet?= Date: Tue, 14 Nov 2023 00:36:37 +0100 Subject: [PATCH] switch confidence interval values --- .../fitters/breslow_fleming_harrington_fitter.py | 10 +++++++++- lifelines/fitters/kaplan_meier_fitter.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lifelines/fitters/breslow_fleming_harrington_fitter.py b/lifelines/fitters/breslow_fleming_harrington_fitter.py index 07b21e5f5..1d205802a 100644 --- a/lifelines/fitters/breslow_fleming_harrington_fitter.py +++ b/lifelines/fitters/breslow_fleming_harrington_fitter.py @@ -72,7 +72,14 @@ def fit( alpha = coalesce(alpha, self.alpha) naf = NelsonAalenFitter(alpha=alpha) - naf.fit(durations, event_observed=event_observed, timeline=timeline, label=self._label, entry=entry, ci_labels=ci_labels) + naf.fit( + durations, + event_observed=event_observed, + timeline=timeline, + label=self._label, + entry=entry, + ci_labels=ci_labels, + ) self.durations, self.event_observed, self.timeline, self.entry, self.event_table, self.weights = ( naf.durations, naf.event_observed, @@ -87,6 +94,7 @@ def fit( self.confidence_interval_ = np.exp(-naf.confidence_interval_) self.confidence_interval_survival_function_ = self.confidence_interval_ self.confidence_interval_cumulative_density = 1 - self.confidence_interval_ + self.confidence_interval_cumulative_density[:] = np.fliplr(self.confidence_interval_cumulative_density.values) # estimation methods self._estimation_method = "survival_function_" diff --git a/lifelines/fitters/kaplan_meier_fitter.py b/lifelines/fitters/kaplan_meier_fitter.py index 7f3974382..8d3f2b17d 100644 --- a/lifelines/fitters/kaplan_meier_fitter.py +++ b/lifelines/fitters/kaplan_meier_fitter.py @@ -351,9 +351,14 @@ def _fit( primary_estimate_name = "survival_function_" secondary_estimate_name = "cumulative_density_" - (self.durations, self.event_observed, self.timeline, self.entry, self.event_table, self.weights) = _preprocess_inputs( - durations, event_observed, timeline, entry, weights - ) + ( + self.durations, + self.event_observed, + self.timeline, + self.entry, + self.event_table, + self.weights, + ) = _preprocess_inputs(durations, event_observed, timeline, entry, weights) alpha = alpha if alpha else self.alpha log_estimate, cumulative_sq_ = _additive_estimate( @@ -386,6 +391,7 @@ def _fit( self.confidence_interval_survival_function_ = self.confidence_interval_ self.confidence_interval_cumulative_density_ = 1 - self.confidence_interval_ + self.confidence_interval_cumulative_density_[:] = np.fliplr(self.confidence_interval_cumulative_density_.values) self._median = median_survival_times(self.survival_function_) self._cumulative_sq_ = cumulative_sq_