Skip to content

Commit

Permalink
Merge pull request #1575 from TheooJ/invert_confidence_intervals
Browse files Browse the repository at this point in the history
switch confidence interval values
  • Loading branch information
CamDavidsonPilon committed Nov 14, 2023
2 parents 716b204 + 2abf0dd commit c9b136b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lifelines/fitters/breslow_fleming_harrington_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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_"
Expand Down
12 changes: 9 additions & 3 deletions lifelines/fitters/kaplan_meier_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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_

Expand Down

0 comments on commit c9b136b

Please sign in to comment.