nodes: 0, module; 1, function_definition; 2, function_name:holm; 3, parameters; 4, block; 5, identifier:pvals; 6, default_parameter; 7, expression_statement; 8, comment:# Convert to array and save original shape; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, comment:# Sort the (flattened) p-values; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, comment:# Now we adjust the p-values; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, comment:# And revert to the original shape and order; 23, expression_statement; 24, expression_statement; 25, with_statement; 26, return_statement; 27, identifier:alpha; 28, float:.05; 29, comment:"""P-values correction with Holm method.
  
      Parameters
      ----------
      pvals : array_like
          Array of p-values of the individual tests.
      alpha : float
          Error rate (= alpha level).
  
      Returns
      -------
      reject : array, bool
          True if a hypothesis is rejected, False if not
      pvals_corrected : array
          P-values adjusted for multiple hypothesis testing using the Holm
          procedure.
  
      See also
      --------
      bonf : Bonferroni correction
      fdr : Benjamini/Hochberg and Benjamini/Yekutieli FDR correction
  
      Notes
      -----
      From Wikipedia:
  
      In statistics, the Holm–Bonferroni method (also called the Holm method) is
      used to counteract the problem of multiple comparisons. It is intended to
      control the family-wise error rate and offers a simple test uniformly more
      powerful than the Bonferroni correction.
  
      The Holm adjusted p-values are the running maximum of the sorted p-values
      divided by the corresponding increasing alpha level:
  
      .. math::
  
          \\frac{\\alpha}{n}, \\frac{\\alpha}{n-1}, ..., \\frac{\\alpha}{1}
  
      where :math:`n` is the number of test.
  
      The full mathematical formula is:
  
      .. math::
          \\widetilde {p}_{{(i)}}=\\max _{{j\\leq i}}\\left\\{(n-j+1)p_{{(j)}}
          \\right\\}_{{1}}
  
      Note that NaN values are not taken into account in the p-values correction.
  
      References
      ----------
      - Holm, S. (1979). A simple sequentially rejective multiple test procedure.
        Scandinavian journal of statistics, 65-70.
  
      - https://en.wikipedia.org/wiki/Holm%E2%80%93Bonferroni_method
  
      Examples
      --------
      >>> from pingouin import holm
      >>> pvals = [.50, .003, .32, .054, .0003]
      >>> reject, pvals_corr = holm(pvals, alpha=.05)
      >>> print(reject, pvals_corr)
      [False  True False False  True] [0.64   0.012  0.64   0.162  0.0015]
      """; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, assignment; 35, assignment; 36, assignment; 37, assignment; 38, assignment; 39, assignment; 40, assignment; 41, assignment; 42, assignment; 43, with_clause; 44, block; 45, expression_list; 46, identifier:pvals; 47, call; 48, identifier:shape_init; 49, attribute; 50, identifier:pvals; 51, call; 52, identifier:num_nan; 53, call; 54, identifier:pvals_sortind; 55, call; 56, identifier:pvals_sorted; 57, subscript; 58, identifier:sortrevind; 59, call; 60, identifier:ntests; 61, binary_operator:pvals.size - num_nan; 62, identifier:pvals_corr; 63, call; 64, identifier:pvals_corr; 65, call; 66, identifier:pvals_corr; 67, call; 68, identifier:pvals_corr; 69, call; 70, identifier:pvals_corrected; 71, call; 72, with_item; 73, expression_statement; 74, identifier:reject; 75, identifier:pvals_corrected; 76, attribute; 77, argument_list; 78, identifier:pvals; 79, identifier:shape; 80, attribute; 81, argument_list; 82, attribute; 83, argument_list; 84, attribute; 85, argument_list; 86, identifier:pvals; 87, identifier:pvals_sortind; 88, attribute; 89, argument_list; 90, attribute; 91, identifier:num_nan; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, call; 103, assignment; 104, identifier:np; 105, identifier:asarray; 106, identifier:pvals; 107, identifier:pvals; 108, identifier:ravel; 109, call; 110, identifier:sum; 111, identifier:np; 112, identifier:argsort; 113, identifier:pvals; 114, identifier:pvals_sortind; 115, identifier:argsort; 116, identifier:pvals; 117, identifier:size; 118, identifier:np; 119, identifier:diag; 120, binary_operator:pvals_sorted * np.arange(ntests, 0, -1)[..., None]; 121, attribute; 122, identifier:accumulate; 123, identifier:pvals_corr; 124, identifier:np; 125, identifier:clip; 126, identifier:pvals_corr; 127, None; 128, integer:1; 129, identifier:np; 130, identifier:append; 131, identifier:pvals_corr; 132, call; 133, subscript; 134, identifier:reshape; 135, identifier:shape_init; 136, attribute; 137, argument_list; 138, identifier:reject; 139, call; 140, attribute; 141, argument_list; 142, identifier:pvals_sorted; 143, subscript; 144, identifier:np; 145, identifier:maximum; 146, attribute; 147, argument_list; 148, identifier:pvals_corr; 149, identifier:sortrevind; 150, identifier:np; 151, identifier:errstate; 152, keyword_argument; 153, attribute; 154, argument_list; 155, identifier:np; 156, identifier:isnan; 157, identifier:pvals; 158, call; 159, ellipsis:...; 160, None; 161, identifier:np; 162, identifier:full; 163, identifier:num_nan; 164, attribute; 165, identifier:invalid; 166, string; 167, identifier:np; 168, identifier:less; 169, identifier:pvals_corrected; 170, identifier:alpha; 171, attribute; 172, argument_list; 173, identifier:np; 174, identifier:nan; 175, string_content:ignore; 176, identifier:np; 177, identifier:arange; 178, identifier:ntests; 179, integer:0; 180, unary_operator; 181, integer:1
code: def holm(pvals, alpha=.05):
      """P-values correction with Holm method.
  
      Parameters
      ----------
      pvals : array_like
          Array of p-values of the individual tests.
      alpha : float
          Error rate (= alpha level).
  
      Returns
      -------
      reject : array, bool
          True if a hypothesis is rejected, False if not
      pvals_corrected : array
          P-values adjusted for multiple hypothesis testing using the Holm
          procedure.
  
      See also
      --------
      bonf : Bonferroni correction
      fdr : Benjamini/Hochberg and Benjamini/Yekutieli FDR correction
  
      Notes
      -----
      From Wikipedia:
  
      In statistics, the Holm–Bonferroni method (also called the Holm method) is
      used to counteract the problem of multiple comparisons. It is intended to
      control the family-wise error rate and offers a simple test uniformly more
      powerful than the Bonferroni correction.
  
      The Holm adjusted p-values are the running maximum of the sorted p-values
      divided by the corresponding increasing alpha level:
  
      .. math::
  
          \\frac{\\alpha}{n}, \\frac{\\alpha}{n-1}, ..., \\frac{\\alpha}{1}
  
      where :math:`n` is the number of test.
  
      The full mathematical formula is:
  
      .. math::
          \\widetilde {p}_{{(i)}}=\\max _{{j\\leq i}}\\left\\{(n-j+1)p_{{(j)}}
          \\right\\}_{{1}}
  
      Note that NaN values are not taken into account in the p-values correction.
  
      References
      ----------
      - Holm, S. (1979). A simple sequentially rejective multiple test procedure.
        Scandinavian journal of statistics, 65-70.
  
      - https://en.wikipedia.org/wiki/Holm%E2%80%93Bonferroni_method
  
      Examples
      --------
      >>> from pingouin import holm
      >>> pvals = [.50, .003, .32, .054, .0003]
      >>> reject, pvals_corr = holm(pvals, alpha=.05)
      >>> print(reject, pvals_corr)
      [False  True False False  True] [0.64   0.012  0.64   0.162  0.0015]
      """
      # Convert to array and save original shape
      pvals = np.asarray(pvals)
      shape_init = pvals.shape
      pvals = pvals.ravel()
      num_nan = np.isnan(pvals).sum()
  
      # Sort the (flattened) p-values
      pvals_sortind = np.argsort(pvals)
      pvals_sorted = pvals[pvals_sortind]
      sortrevind = pvals_sortind.argsort()
      ntests = pvals.size - num_nan
  
      # Now we adjust the p-values
      pvals_corr = np.diag(pvals_sorted * np.arange(ntests, 0, -1)[..., None])
      pvals_corr = np.maximum.accumulate(pvals_corr)
      pvals_corr = np.clip(pvals_corr, None, 1)
  
      # And revert to the original shape and order
      pvals_corr = np.append(pvals_corr, np.full(num_nan, np.nan))
      pvals_corrected = pvals_corr[sortrevind].reshape(shape_init)
      with np.errstate(invalid='ignore'):
          reject = np.less(pvals_corrected, alpha)
      return reject, pvals_corrected