code: def posthoc_tukey_hsd(
      x: Union[list, np.ndarray, DataFrame], g: str, alpha: float = 0.05
  ) -> DataFrame:
      """Pairwise comparisons with TukeyHSD confidence intervals. This is a
      convenience function to make statsmodels `pairwise_tukeyhsd` method more
      applicable for further use.
  
      Parameters
      ----------
      x : array_like or pandas Series object, 1d
          An array, any object exposing the array interface, containing dependent
          variable values (test or response variable). Values should have a
          non-nominal scale. NaN values will cause an error (please handle
          manually).
  
      g : array_like or pandas Series object, 1d
          An array, any object exposing the array interface, containing
          independent variable values (grouping or predictor variable). Values
          should have a nominal scale (categorical).
  
      alpha : float, optional
          Significance level for the test. Default is 0.05.
  
      Returns
      -------
      result : pandas.DataFrame
          DataFrame with 0, 1, and -1 values, where 0 is False (not significant),
          1 is True (significant), and -1 is for diagonal elements.
  
      Examples
      --------
      >>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
      >>> g = [['a'] * 5, ['b'] * 5, ['c'] * 5]
      >>> sp.posthoc_tukey_hsd(np.concatenate(x), np.concatenate(g))
      """
      result = pairwise_tukeyhsd(x, g, alpha=alpha)
      groups = np.array(result.groupsunique, dtype=str)
      groups_len = len(groups)
  
      vs = np.zeros((groups_len, groups_len), dtype=int)
  
      for a in result.summary()[1:]:
          a0 = str(a[0])
          a1 = str(a[1])
          a0i = np.where(groups == a0)[0][0]
          a1i = np.where(groups == a1)[0][0]
          vs[a0i, a1i] = 1 if str(a[-1]) == "True" else 0
  
      vsu = np.triu(vs)
      np.fill_diagonal(vsu, 1)
      tri_lower = np.tril_indices(vsu.shape[0], -1)
      vsu[tri_lower] = np.transpose(vsu)[tri_lower]
      return DataFrame(vsu, index=groups, columns=groups)
  
imports: import itertools
  from typing import Tuple, Union
  import numpy
  import scipy.stats
  from statsmodels.sandbox.stats.multicomp import multipletests
  from statsmodels.stats.multicomp import pairwise_tukeyhsd
  from statsmodels.stats.libqsturng import psturng
  from pandas import DataFrame
label_desc: Use image node_id 16 for calling a global function with example usage: posthoc_tukey_hsd(x, g, alpha) and returns: DataFrame