code: def pairwise_logrank_test(
      event_durations,
      groups,
      event_observed=None,
      t_0=-1,
      weightings=None,
      **kwargs,
  ) -> StatisticalResult:  # pylint: disable=too-many-locals
      r"""
      Perform the logrank test pairwise for all :math:`n \ge 2` unique groups.
  
      Parameters
      ----------
  
      event_durations: iterable
          a (n,) list-like representing the (possibly partial) durations of all individuals
  
      groups: iterable
          a (n,) list-like of unique group labels for each individual.
  
      event_observed: iterable, optional
          a (n,) list-like of event_observed events: 1 if observed death, 0 if censored. Defaults to all observed.
  
      t_0: float, optional (default=-1)
          The final time period under observation, and subjects who experience the event after this time are set to be censored.
          Specify -1 to use all time.
  
      weightings: str, optional
          apply a weighted logrank test: options are "wilcoxon" for Wilcoxon (also known as Breslow), "tarone-ware"
          for Tarone-Ware, "peto" for Peto test and "fleming-harrington" for Fleming-Harrington test.
          These are useful for testing for early or late differences in the survival curve. For the Fleming-Harrington
          test, keyword arguments p and q must also be provided with non-negative values.
  
          Weightings are applied at the ith ordered failure time, :math:`t_{i}`, according to:
              Wilcoxon: :math:`n_i`
              Tarone-Ware: :math:`\sqrt{n_i}`
              Peto: :math:`\bar{S}(t_i)`
              Fleming-Harrington: :math:`\hat{S}(t_i)^p \times (1 - \hat{S}(t_i))^q`
  
              where :math:`n_i` is the number at risk just prior to time :math:`t_{i}`, :math:`\bar{S}(t_i)` is
              Peto-Peto's modified survival estimate and :math:`\hat{S}(t_i)` is the left-continuous
              Kaplan-Meier survival estimate at time :math:`t_{i}`.
      kwargs:
          add keywords and meta-data to the experiment summary.
  
  
      Returns
      -------
  
      StatisticalResult
          a StatisticalResult object that contains all the pairwise comparisons (try ``StatisticalResult.summary`` or ``StatisticalResult.print_summary``)
  
  
      See Also
      --------
      multivariate_logrank_test
      logrank_test
      """
  
      if event_observed is None:
          event_observed = np.ones((event_durations.shape[0], 1))
  
      n = np.max(np.asarray(event_durations).shape)
  
      groups, event_durations, event_observed = map(
          lambda x: np.asarray(x).reshape(n),
          [groups, event_durations, event_observed],
      )
  
      if not (n == event_durations.shape[0] == event_observed.shape[0]):
          raise ValueError("inputs must be of the same length.")
  
      groups, event_durations, event_observed = (
          pd.Series(groups),
          pd.Series(event_durations),
          pd.Series(event_observed),
      )
  
      unique_groups = np.unique(groups)
  
      n_unique_groups = unique_groups.shape[0]
  
      result = StatisticalResult(
          [], [], [], test_name="pairwise_logrank_test"
      )
  
      for i1, i2 in combinations(np.arange(n_unique_groups), 2):
          g1, g2 = unique_groups[[i1, i2]]
          ix1, ix2 = (groups == g1), (groups == g2)
          result += logrank_test(
              event_durations.loc[ix1],
              event_durations.loc[ix2],
              event_observed.loc[ix1],
              event_observed.loc[ix2],
              t_0=t_0,
              name=[(g1, g2)],
              weightings=weightings,
              **kwargs,
          )
  
      return result
  
imports: from itertools import combinations
  import warnings
  import numpy
  from scipy import stats
  import pandas
  from lifelines import utils
  from lifelines.utils import group_survival_table_from_events, string_rjustify, format_p_value, format_floats, interpolate_at_times_and_return_pandas, _expected_value_of_survival_up_to_t, _expected_value_of_survival_squared_up_to_t
  from lifelines import KaplanMeierFitter
label_desc: Use image node_id 5 for calling a global function with example usage: pairwise_logrank_test(event_durations, groups, event_observed, t_0, weightings) and returns: result