spectral_connectivity.statistics.adjust_for_multiple_comparisons#

adjust_for_multiple_comparisons(p_values: NDArray[floating], alpha: float = 0.05, method: Literal['Benjamini_Hochberg_procedure', 'Bonferroni_correction'] = 'Benjamini_Hochberg_procedure', *, axis: int | tuple[int, ...] | None = None) → NDArray[bool][source]#

Apply multiple comparison correction to p-values.

Wrapper function that applies the specified multiple comparison correction method to control either false discovery rate or family-wise error rate.

Parameters:
  • p_values (NDArray[floating], shape (...,)) – P-values from statistical tests to be corrected.

  • alpha (float, default=0.05) – Significance threshold for the correction method.

  • method ({"Benjamini_Hochberg_procedure", "Bonferroni_correction"},) – default=”Benjamini_Hochberg_procedure” Multiple comparison correction method to apply.

  • axis (int or tuple of int or None, default=None) – The axes whose tests form one family, as in scipy.stats.false_discovery_control(): each slice along the remaining axes is corrected on its own. None (the default) pools every p-value into a single family. For p-values shaped (n_time_windows, n_frequencies), axis=-1 corrects across frequencies separately in each time window.

Returns:

is_significant – Boolean array indicating which tests remain significant after correction.

Return type:

NDArray[bool], shape (…,)

Notes

A family per slice controls errors only within each slice. With axis, the false discovery rate (or family-wise error rate) is held at alpha in each family separately, not across them: for null p-values shaped (100, 126) (time windows, frequencies), axis=-1 gives at least one false rejection somewhere in 99% of simulated datasets, against 5% when pooled. Choose the families before looking at the results, to match the claims you will make: one per slice when each slice is a separate question, the pooled default when results across slices are reported together. Keeping only the slices with a discovery and then reporting results within them is a selection that needs its own adjustment (Benjamini and Bogomolov [1]).

Test each pair once. A matrix of p-values over (source, target) holds a signal’s coherence with itself (p = 0) on its diagonal and every undirected pair twice. The diagonal’s sure rejections loosen the Benjamini-Hochberg threshold for the real pairs: with 16 signals and no coupling, some pair is declared significant in 35% of simulated datasets, against 6% for the upper triangle alone. Pass the pairs once, e.g. p_values[(..., *np.triu_indices(n_signals, 1))], with the pair axis in the family.

Dependence. P-values at neighboring frequencies (within the taper bandwidth), in overlapping windows, and of pairs sharing a signal are positively correlated. Bonferroni holds under any dependence, at the cost of power; Benjamini-Hochberg is guaranteed for independent or positively regression-dependent tests (Benjamini and Yekutieli [2]).

References

[1]

Benjamini, Y., and Bogomolov, M. (2014). Selective inference on multiple families of hypotheses. Journal of the Royal Statistical Society: Series B 76, 297-318.

[2]

Benjamini, Y., and Yekutieli, D. (2001). The control of the false discovery rate in multiple testing under dependency. The Annals of Statistics 29, 1165-1188.

Examples

>>> import numpy as np
>>> p_vals = np.array([0.001, 0.02, 0.04, 0.3, 0.8])
>>> # Using Benjamini-Hochberg (default)
>>> bh_sig = adjust_for_multiple_comparisons(p_vals)
>>> # Using Bonferroni
>>> bonf_sig = adjust_for_multiple_comparisons(
...     p_vals, method="Bonferroni_correction"
... )

One family per row (say, per time window) instead of one for the whole array. The second row’s 0.015 passes Bonferroni among its own three tests (0.05 / 3) but not among all six (0.05 / 6):

>>> p_vals = np.array([[0.001, 0.2, 0.5], [0.015, 0.6, 0.9]])
>>> adjust_for_multiple_comparisons(p_vals, method="Bonferroni_correction")
array([[ True, False, False],
       [False, False, False]])
>>> adjust_for_multiple_comparisons(p_vals, method="Bonferroni_correction", axis=-1)
array([[ True, False, False],
       [ True, False, False]])