You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
n_permutations="all" in the cluster permutation tests does not run the full exact test #14479
For "all" the number of permutations is set to the number of non-identity sign flips and then the code draws that many minus one of them at random, so one flip pattern is left out and the surrogate distribution is one entry short. Passing an integer larger than the number of possible flips enumerates all of them correctly.
For a two-tailed test on 8 subjects there are 2**(8 - 1) = 128 distinct sign patterns, so the exact test has 128 surrogate values and p-values that are multiples of 1/128 (here 3/128 = 0.0234375).
Actual results
n_permutations="all" returns 127 surrogate values and 3/127 = 0.02362. The result is not the exact permutation distribution the documentation promises.
Additional information
I used AI to help me locate this may be due to mne/stats/cluster_level.py, _get_1samp_orders:
max_perms=2** (n_samples- (tail==0)) -1ifisinstance(n_permutations, str):
...
n_permutations=max_perms# "all"n_permutations=int(n_permutations)
ifmax_perms<n_permutations: # False for "all"orders=bin_perm_rep(n_samples)[1 : max_perms+1] # exact enumerationelifn_samples<=20:
orders=rng.choice(max_perms, n_permutations-1, replace=False) # random draw, one pattern fewer
Activity
larsoner commentedon Nov 2, 2026
I'll take a look, this sounds like we need to include the original permutation in H0 but not actually recompute it...