Skip to content

Fix permutation p-values missing tied permutations in compute_pvals_perm - #1373

Open
ptlnextdoor wants to merge 1 commit into
NeuroTechX:developfrom
ptlnextdoor:fix/oss-moabb-perm-test-ties
Open

ptlnextdoor wants to merge 1 commit into
NeuroTechX:developfrom
ptlnextdoor:fix/oss-moabb-perm-test-ties

Conversation

@ptlnextdoor

Copy link
Copy Markdown

What was wrong

_pairedttest_exact and _pairedttest_random compare the permuted sums (perms @ data) with the observed sum (data.sum(axis=0)). The two are computed differently, so they differ by rounding error and a permutation that ties with the observed sum can fall just below it. Tied permutations then drop out of the count and the p-value is too small. Accuracy-type scores are multiples of 1/n_trials, so ties are common. compute_dataset_statistics uses this test for every dataset with fewer than 20 subjects, and the p-values feed Stouffer's method and the meta-analysis plots.

Example (8 subjects, scores out of 20): the exact p-value is 8/256 = 0.03125, and compute_pvals_perm on develop returns 7/256 = 0.02734375. In 300 random 10-subject datasets, 221 had a p-value that differed from an integer-arithmetic reference on develop and none after this change. The pre-#1345 loop version has the same problem, so this is not a regression from the vectorization.

What changed

Both functions compare randperms >= true - tol, with tol = 1e-9 * np.abs(data).sum(axis=0), a tolerance relative to the summed absolute differences. P-values of datasets with fewer than 20 subjects get larger (correct) when scores tie.

Alternative if you prefer it: round the scores to the trial grid before the test. That needs the number of trials, which compute_pvals_perm does not have.

Adds a whats_new entry under Bugs.

How tested

  • New test test_perm_exhaustive_counts_tied_permutations expects 8/256. It fails on develop (0.02734375) and passes with the change.
  • pytest moabb/tests/test_analysis.py passes (69 tests).
  • pre-commit run --files on the three changed files passes.

AI disclosure: this PR was prepared with AI assistance (Claude, Anthropic).

Permuted sums come from perms @ data and the observed sum from data.sum, so rounding drops exact ties from the count. The comparison now uses a tolerance relative to the summed absolute differences.
Copilot AI balanced review requested due to automatic review settings November 24, 2026 21:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants