Repository navigation
Fix permutation p-values missing tied permutations in compute_pvals_perm - #1373
Open
ptlnextdoor wants to merge 1 commit into
Open
ptlnextdoor wants to merge 1 commit into
ptlnextdoor wants to merge 1 commit into
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
_pairedttest_exactand_pairedttest_randomcompare 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_statisticsuses 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_permon 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, withtol = 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_permdoes not have.Adds a
whats_newentry under Bugs.How tested
test_perm_exhaustive_counts_tied_permutationsexpects 8/256. It fails on develop (0.02734375) and passes with the change.pytest moabb/tests/test_analysis.pypasses (69 tests).pre-commit run --fileson the three changed files passes.AI disclosure: this PR was prepared with AI assistance (Claude, Anthropic).