-
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
base: develop
Are you sure you want to change the base?
Changes from 7 commits
25d1022
0667dc6
c7114de
4d546f7
7a7c4f4
a5e6160
9495ae0
507d028
14c04a6
d199d2b
8b94e0d
acb565a
d2518e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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]), dtype=np.int32) | ||||||||
true = data.sum(axis=0) | ||||||||
nperms = 2 ** data.shape[0] | ||||||||
for perm in itertools.product([-1, 1], repeat=data.shape[0]): | ||||||||
|
@@ -98,11 +98,10 @@ 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 = out / nperms | ||||||||
# control for cases where pval is 1 | ||||||||
out[out == 1] = 1 - (1 / nperms) | ||||||||
return out | ||||||||
out += randperm >= true | ||||||||
|
||||||||
out[out >= nperms] = nperms - 1 | ||||||||
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. You could add another control to avoid a p-value equal to 0:
Suggested change
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. I agree this may deserve a comment in the code. If |
||||||||
return out / nperms | ||||||||
|
||||||||
|
||||||||
def _pairedttest_random(data, nperms): | ||||||||
|
@@ -121,16 +120,19 @@ 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.ones( | ||||||||
(data.shape[1], data.shape[1]), dtype=np.int32 | ||||||||
) # we use ones() so that out is never 0 | ||||||||
gcattan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
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[out == nperms] = nperms - 1 | ||||||||
out += randperm >= true | ||||||||
|
||||||||
out[out >= nperms] = nperms - 1 | ||||||||
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.
Suggested change
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. Here also, I will add a comment. |
||||||||
return out / nperms | ||||||||
|
||||||||
|
||||||||
|
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.
Initialization of
out
should be similar between_pairedttest_exhaustive
and_pairedttest_random
: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.
Hm ok. But then we will take into account the original statistic two times, as we have
random >= true