-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct permutation t-tests #684
Draft
gcattan
wants to merge
13
commits into
NeuroTechX:develop
Choose a base branch
from
gcattan:patch-2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
25d1022
Correct permutation t-tests
gcattan 0667dc6
Update meta_analysis.py
gcattan c7114de
Merge branch 'develop' into patch-2
bruAristimunha 4d546f7
Update meta_analysis.py
toncho11 7a7c4f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a5e6160
Update meta_analysis.py
toncho11 9495ae0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 507d028
Apply suggestions from code review
gcattan 14c04a6
Update meta_analysis.py
gcattan d199d2b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8b94e0d
Merge branch 'develop' into patch-2
bruAristimunha acb565a
Update meta_analysis.py
gcattan d2518e2
Update moabb/analysis/meta_analysis.py
gcattan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ def _pairedttest_exhaustive(data): | |
pvals: ndarray of shape (n_pipelines, n_pipelines) | ||
array of pvalues | ||
""" | ||
out = np.ones((data.shape[1], data.shape[1])) | ||
out = np.zeros((data.shape[1], data.shape[1])) | ||
true = data.sum(axis=0) | ||
nperms = 2 ** data.shape[0] | ||
for perm in itertools.product([-1, 1], repeat=data.shape[0]): | ||
|
@@ -98,7 +98,7 @@ def _pairedttest_exhaustive(data): | |
# multiply permutation by subject dimension and sum over subjects | ||
randperm = (data * perm[:, None, None]).sum(axis=0) | ||
# compare to true difference (numpy autocasts bool to 0/1) | ||
out += randperm > true | ||
out += randperm >= true | ||
out = out / nperms | ||
# control for cases where pval is 1 | ||
out[out == 1] = 1 - (1 / nperms) | ||
|
@@ -121,15 +121,15 @@ def _pairedttest_random(data, nperms): | |
pvals: ndarray of shape (n_pipelines, n_pipelines) | ||
array of pvalues | ||
""" | ||
out = np.ones((data.shape[1], data.shape[1])) | ||
out = np.zeros((data.shape[1], data.shape[1])) | ||
true = data.sum(axis=0) | ||
for _ in range(nperms): | ||
perm = np.random.randint(2, size=(data.shape[0],)) | ||
perm[perm == 0] = -1 | ||
# multiply permutation by subject dimension and sum over subjects | ||
randperm = (data * perm[:, None, None]).sum(axis=0) | ||
# compare to true difference (numpy autocasts bool to 0/1) | ||
out += randperm > true | ||
out += randperm >= true | ||
out[out == nperms] = nperms - 1 | ||
return out / nperms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be |
||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of exhaustive, this is not necessary.
But in the case of random, the initial statistic is not necessarily among those found within the permutation distribution.