nodes: 0, module; 1, function_definition; 2, function_name:posthoc_mannwhitney; 3, parameters; 4, block; 5, identifier:a; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, for_statement; 24, if_statement; 25, expression_statement; 26, expression_statement; 27, return_statement; 28, identifier:val_col; 29, None; 30, identifier:group_col; 31, None; 32, identifier:use_continuity; 33, True; 34, identifier:alternative; 35, string; 36, identifier:p_adjust; 37, None; 38, identifier:sort; 39, True; 40, string; 41, assignment; 42, not_operator; 43, block; 44, call; 45, assignment; 46, assignment; 47, assignment; 48, assignment; 49, assignment; 50, assignment; 51, assignment; 52, pattern_list; 53, identifier:combs; 54, block; 55, identifier:p_adjust; 56, block; 57, assignment; 58, call; 59, call; 60, string_content:two-sided; 61, string_content:Pairwise comparisons with Mann-Whitney rank test.
  
      Parameters
      ----------
      a : array_like or pandas DataFrame object
          An array, any object exposing the array interface or a pandas
          DataFrame. Array must be two-dimensional.
  
      val_col : str, optional
          Name of a DataFrame column that contains dependent variable values (test
          or response variable). Values should have a non-nominal scale. Must be
          specified if `a` is a pandas DataFrame object.
  
      group_col : str, optional
          Name of a DataFrame column that contains independent variable values
          (grouping or predictor variable). Values should have a nominal scale
          (categorical). Must be specified if `a` is a pandas DataFrame object.
  
      use_continuity : bool, optional
          Whether a continuity correction (1/2.) should be taken into account.
          Default is True.
  
      alternative : ['two-sided', 'less', or 'greater'], optional
          Whether to get the p-value for the one-sided hypothesis
          ('less' or 'greater') or for the two-sided hypothesis ('two-sided').
          Defaults to 'two-sided'.
  
      p_adjust : str, optional
          Method for adjusting p values.
          See statsmodels.sandbox.stats.multicomp for details.
          Available methods are:
          'bonferroni' : one-step correction
          'sidak' : one-step correction
          'holm-sidak' : step-down method using Sidak adjustments
          'holm' : step-down method using Bonferroni adjustments
          'simes-hochberg' : step-up method  (independent)
          'hommel' : closed method based on Simes tests (non-negative)
          'fdr_bh' : Benjamini/Hochberg  (non-negative)
          'fdr_by' : Benjamini/Yekutieli (negative)
          'fdr_tsbh' : two stage fdr correction (non-negative)
          'fdr_tsbky' : two stage fdr correction (non-negative)
  
      sort : bool, optional
          Specifies whether to sort DataFrame by group_col or not. Recommended
          unless you sort your data manually.
  
      Returns
      -------
      result : pandas DataFrame
          P values.
  
      Notes
      -----
      Refer to `scipy.stats.mannwhitneyu` reference page for further details.
  
      Examples
      --------
      >>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
      >>> sp.posthoc_mannwhitney(x, p_adjust = 'holm'); 62, pattern_list; 63, call; 64, identifier:sort; 65, expression_statement; 66, attribute; 67, argument_list; 68, identifier:groups; 69, call; 70, identifier:x_len; 71, attribute; 72, identifier:vs; 73, call; 74, identifier:tri_upper; 75, call; 76, identifier:tri_lower; 77, call; 78, subscript; 79, integer:0; 80, identifier:combs; 81, call; 82, identifier:i; 83, identifier:j; 84, expression_statement; 85, expression_statement; 86, subscript; 87, subscript; 88, attribute; 89, argument_list; 90, identifier:DataFrame; 91, argument_list; 92, identifier:x; 93, identifier:_val_col; 94, identifier:_group_col; 95, identifier:__convert_to_df; 96, argument_list; 97, assignment; 98, identifier:x; 99, identifier:sort_values; 100, keyword_argument; 101, keyword_argument; 102, keyword_argument; 103, attribute; 104, argument_list; 105, identifier:groups; 106, identifier:size; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, attribute; 112, argument_list; 113, identifier:vs; 114, slice; 115, slice; 116, attribute; 117, argument_list; 118, assignment; 119, assignment; 120, identifier:vs; 121, identifier:tri_lower; 122, attribute; 123, identifier:tri_lower; 124, identifier:np; 125, identifier:fill_diagonal; 126, identifier:vs; 127, unary_operator; 128, identifier:vs; 129, keyword_argument; 130, keyword_argument; 131, identifier:a; 132, identifier:val_col; 133, identifier:group_col; 134, subscript; 135, call; 136, identifier:by; 137, list; 138, identifier:ascending; 139, True; 140, identifier:inplace; 141, True; 142, identifier:np; 143, identifier:unique; 144, subscript; 145, identifier:np; 146, identifier:zeros; 147, tuple; 148, identifier:np; 149, identifier:triu_indices; 150, subscript; 151, integer:1; 152, identifier:np; 153, identifier:tril_indices; 154, subscript; 155, unary_operator; 156, identifier:it; 157, identifier:combinations; 158, call; 159, integer:2; 160, subscript; 161, subscript; 162, subscript; 163, subscript; 164, identifier:vs; 165, identifier:T; 166, integer:1; 167, identifier:index; 168, identifier:groups; 169, identifier:columns; 170, identifier:groups; 171, identifier:x; 172, identifier:_group_col; 173, identifier:Categorical; 174, argument_list; 175, identifier:_group_col; 176, identifier:_val_col; 177, identifier:x; 178, identifier:_group_col; 179, identifier:x_len; 180, identifier:x_len; 181, attribute; 182, integer:0; 183, attribute; 184, integer:0; 185, integer:1; 186, identifier:range; 187, argument_list; 188, identifier:vs; 189, identifier:i; 190, identifier:j; 191, call; 192, integer:1; 193, identifier:vs; 194, identifier:tri_upper; 195, call; 196, integer:1; 197, subscript; 198, keyword_argument; 199, keyword_argument; 200, identifier:vs; 201, identifier:shape; 202, identifier:vs; 203, identifier:shape; 204, identifier:x_len; 205, attribute; 206, argument_list; 207, identifier:multipletests; 208, argument_list; 209, identifier:x; 210, identifier:_group_col; 211, identifier:categories; 212, call; 213, identifier:ordered; 214, True; 215, identifier:ss; 216, identifier:mannwhitneyu; 217, subscript; 218, subscript; 219, keyword_argument; 220, keyword_argument; 221, subscript; 222, keyword_argument; 223, attribute; 224, argument_list; 225, attribute; 226, comparison_operator:x[_group_col] == groups[i]; 227, identifier:_val_col; 228, attribute; 229, comparison_operator:x[_group_col] == groups[j]; 230, identifier:_val_col; 231, identifier:use_continuity; 232, identifier:use_continuity; 233, identifier:alternative; 234, identifier:alternative; 235, identifier:vs; 236, identifier:tri_upper; 237, identifier:method; 238, identifier:p_adjust; 239, subscript; 240, identifier:unique; 241, identifier:x; 242, identifier:loc; 243, subscript; 244, subscript; 245, identifier:x; 246, identifier:loc; 247, subscript; 248, subscript; 249, identifier:x; 250, identifier:_group_col; 251, identifier:x; 252, identifier:_group_col; 253, identifier:groups; 254, identifier:i; 255, identifier:x; 256, identifier:_group_col; 257, identifier:groups; 258, identifier:j
code: def posthoc_mannwhitney(a, val_col=None, group_col=None, use_continuity=True, alternative='two-sided', p_adjust=None, sort=True):
  
      '''Pairwise comparisons with Mann-Whitney rank test.
  
      Parameters
      ----------
      a : array_like or pandas DataFrame object
          An array, any object exposing the array interface or a pandas
          DataFrame. Array must be two-dimensional.
  
      val_col : str, optional
          Name of a DataFrame column that contains dependent variable values (test
          or response variable). Values should have a non-nominal scale. Must be
          specified if `a` is a pandas DataFrame object.
  
      group_col : str, optional
          Name of a DataFrame column that contains independent variable values
          (grouping or predictor variable). Values should have a nominal scale
          (categorical). Must be specified if `a` is a pandas DataFrame object.
  
      use_continuity : bool, optional
          Whether a continuity correction (1/2.) should be taken into account.
          Default is True.
  
      alternative : ['two-sided', 'less', or 'greater'], optional
          Whether to get the p-value for the one-sided hypothesis
          ('less' or 'greater') or for the two-sided hypothesis ('two-sided').
          Defaults to 'two-sided'.
  
      p_adjust : str, optional
          Method for adjusting p values.
          See statsmodels.sandbox.stats.multicomp for details.
          Available methods are:
          'bonferroni' : one-step correction
          'sidak' : one-step correction
          'holm-sidak' : step-down method using Sidak adjustments
          'holm' : step-down method using Bonferroni adjustments
          'simes-hochberg' : step-up method  (independent)
          'hommel' : closed method based on Simes tests (non-negative)
          'fdr_bh' : Benjamini/Hochberg  (non-negative)
          'fdr_by' : Benjamini/Yekutieli (negative)
          'fdr_tsbh' : two stage fdr correction (non-negative)
          'fdr_tsbky' : two stage fdr correction (non-negative)
  
      sort : bool, optional
          Specifies whether to sort DataFrame by group_col or not. Recommended
          unless you sort your data manually.
  
      Returns
      -------
      result : pandas DataFrame
          P values.
  
      Notes
      -----
      Refer to `scipy.stats.mannwhitneyu` reference page for further details.
  
      Examples
      --------
      >>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
      >>> sp.posthoc_mannwhitney(x, p_adjust = 'holm')
  
      '''
  
      x, _val_col, _group_col = __convert_to_df(a, val_col, group_col)
  
      if not sort:
          x[_group_col] = Categorical(x[_group_col], categories=x[_group_col].unique(), ordered=True)
  
      x.sort_values(by=[_group_col, _val_col], ascending=True, inplace=True)
  
      groups = np.unique(x[_group_col])
      x_len = groups.size
      vs = np.zeros((x_len, x_len))
      tri_upper = np.triu_indices(vs.shape[0], 1)
      tri_lower = np.tril_indices(vs.shape[0], -1)
      vs[:,:] = 0
  
      combs = it.combinations(range(x_len), 2)
  
      for i,j in combs:
          vs[i, j] = ss.mannwhitneyu(x.loc[x[_group_col] == groups[i], _val_col],
                                      x.loc[x[_group_col] == groups[j], _val_col],
                                      use_continuity=use_continuity,
                                      alternative=alternative)[1]
  
      if p_adjust:
          vs[tri_upper] = multipletests(vs[tri_upper], method = p_adjust)[1]
  
      vs[tri_lower] = vs.T[tri_lower]
      np.fill_diagonal(vs, -1)
      return DataFrame(vs, index=groups, columns=groups)