nodes: 0, module; 1, function_definition; 2, function_name:posthoc_wilcoxon; 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, comment:#x.sort_values(by=[_group_col, _val_col], ascending=True, inplace=True); 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:zero_method; 33, string; 34, identifier:correction; 35, False; 36, identifier:p_adjust; 37, None; 38, identifier:sort; 39, False; 40, string:'''Pairwise comparisons with Wilcoxon signed-rank test. It is a non-parametric
      version of the paired T-test for use with non-parametric ANOVA.
  
      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.
  
      zero_method : string, {"pratt", "wilcox", "zsplit"}, optional
          "pratt": Pratt treatment, includes zero-differences in the ranking
          process (more conservative)
          "wilcox": Wilcox treatment, discards all zero-differences
          "zsplit": Zero rank split, just like Pratt, but spliting the zero rank
          between positive and negative ones
  
      correction : bool, optional
          If True, apply continuity correction by adjusting the Wilcoxon rank
          statistic by 0.5 towards the mean value when computing the z-statistic.
          Default is False.
  
      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 and val_col or not.
          Default is False.
  
      Returns
      -------
      result : pandas DataFrame
          P values.
  
      Notes
      -----
      Refer to `scipy.stats.wilcoxon` reference page for further details.
  
      Examples
      --------
      >>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
      >>> sp.posthoc_wilcoxon(x)
  
      '''; 41, assignment; 42, not_operator; 43, block; 44, assignment; 45, assignment; 46, assignment; 47, assignment; 48, assignment; 49, assignment; 50, assignment; 51, pattern_list; 52, identifier:combs; 53, block; 54, identifier:p_adjust; 55, block; 56, assignment; 57, call; 58, call; 59, string_content:wilcox; 60, pattern_list; 61, call; 62, identifier:sort; 63, expression_statement; 64, identifier:groups; 65, call; 66, identifier:x_len; 67, attribute; 68, identifier:vs; 69, call; 70, identifier:tri_upper; 71, call; 72, identifier:tri_lower; 73, call; 74, subscript; 75, integer:0; 76, identifier:combs; 77, call; 78, identifier:i; 79, identifier:j; 80, expression_statement; 81, expression_statement; 82, subscript; 83, subscript; 84, attribute; 85, argument_list; 86, identifier:DataFrame; 87, argument_list; 88, identifier:x; 89, identifier:_val_col; 90, identifier:_group_col; 91, identifier:__convert_to_df; 92, argument_list; 93, assignment; 94, attribute; 95, argument_list; 96, identifier:groups; 97, identifier:size; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, attribute; 103, argument_list; 104, identifier:vs; 105, slice; 106, slice; 107, attribute; 108, argument_list; 109, assignment; 110, assignment; 111, identifier:vs; 112, identifier:tri_lower; 113, attribute; 114, identifier:tri_lower; 115, identifier:np; 116, identifier:fill_diagonal; 117, identifier:vs; 118, unary_operator; 119, identifier:vs; 120, keyword_argument; 121, keyword_argument; 122, identifier:a; 123, identifier:val_col; 124, identifier:group_col; 125, subscript; 126, call; 127, identifier:np; 128, identifier:unique; 129, subscript; 130, identifier:np; 131, identifier:zeros; 132, tuple; 133, identifier:np; 134, identifier:triu_indices; 135, subscript; 136, integer:1; 137, identifier:np; 138, identifier:tril_indices; 139, subscript; 140, unary_operator; 141, identifier:it; 142, identifier:combinations; 143, call; 144, integer:2; 145, subscript; 146, subscript; 147, subscript; 148, subscript; 149, identifier:vs; 150, identifier:T; 151, integer:1; 152, identifier:index; 153, identifier:groups; 154, identifier:columns; 155, identifier:groups; 156, identifier:x; 157, identifier:_group_col; 158, identifier:Categorical; 159, argument_list; 160, identifier:x; 161, identifier:_group_col; 162, identifier:x_len; 163, identifier:x_len; 164, attribute; 165, integer:0; 166, attribute; 167, integer:0; 168, integer:1; 169, identifier:range; 170, argument_list; 171, identifier:vs; 172, identifier:i; 173, identifier:j; 174, call; 175, integer:1; 176, identifier:vs; 177, identifier:tri_upper; 178, call; 179, integer:1; 180, subscript; 181, keyword_argument; 182, keyword_argument; 183, identifier:vs; 184, identifier:shape; 185, identifier:vs; 186, identifier:shape; 187, identifier:x_len; 188, attribute; 189, argument_list; 190, identifier:multipletests; 191, argument_list; 192, identifier:x; 193, identifier:_group_col; 194, identifier:categories; 195, call; 196, identifier:ordered; 197, True; 198, identifier:ss; 199, identifier:wilcoxon; 200, subscript; 201, subscript; 202, keyword_argument; 203, keyword_argument; 204, subscript; 205, keyword_argument; 206, attribute; 207, argument_list; 208, attribute; 209, comparison_operator:x[_group_col] == groups[i]; 210, identifier:_val_col; 211, attribute; 212, comparison_operator:x[_group_col] == groups[j]; 213, identifier:_val_col; 214, identifier:zero_method; 215, identifier:zero_method; 216, identifier:correction; 217, identifier:correction; 218, identifier:vs; 219, identifier:tri_upper; 220, identifier:method; 221, identifier:p_adjust; 222, subscript; 223, identifier:unique; 224, identifier:x; 225, identifier:loc; 226, subscript; 227, subscript; 228, identifier:x; 229, identifier:loc; 230, subscript; 231, subscript; 232, identifier:x; 233, identifier:_group_col; 234, identifier:x; 235, identifier:_group_col; 236, identifier:groups; 237, identifier:i; 238, identifier:x; 239, identifier:_group_col; 240, identifier:groups; 241, identifier:j
code: def posthoc_wilcoxon(a, val_col=None, group_col=None, zero_method='wilcox', correction=False, p_adjust=None, sort=False):
  
      '''Pairwise comparisons with Wilcoxon signed-rank test. It is a non-parametric
      version of the paired T-test for use with non-parametric ANOVA.
  
      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.
  
      zero_method : string, {"pratt", "wilcox", "zsplit"}, optional
          "pratt": Pratt treatment, includes zero-differences in the ranking
          process (more conservative)
          "wilcox": Wilcox treatment, discards all zero-differences
          "zsplit": Zero rank split, just like Pratt, but spliting the zero rank
          between positive and negative ones
  
      correction : bool, optional
          If True, apply continuity correction by adjusting the Wilcoxon rank
          statistic by 0.5 towards the mean value when computing the z-statistic.
          Default is False.
  
      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 and val_col or not.
          Default is False.
  
      Returns
      -------
      result : pandas DataFrame
          P values.
  
      Notes
      -----
      Refer to `scipy.stats.wilcoxon` reference page for further details.
  
      Examples
      --------
      >>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
      >>> sp.posthoc_wilcoxon(x)
  
      '''
  
      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.wilcoxon(x.loc[x[_group_col] == groups[i], _val_col],
                                 x.loc[x[_group_col] == groups[j], _val_col],
                                 zero_method=zero_method, correction=correction)[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)