Skip to content

Commit

Permalink
add group to permutation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebarachant committed Jun 21, 2017
1 parent 92531c5 commit 22ee36d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pyriemann/stats.py
Expand Up @@ -100,6 +100,17 @@ def _initial_transform(self, X):
"""Initial transformation. By default return X."""
return X

def _shuffle(self, y, groups, rs):
"""Return a shuffled copy of y eventually shuffle among same groups."""
if groups is None:
indices = rs.permutation(len(y))
else:
indices = numpy.arange(len(groups))
for group in numpy.unique(groups):
this_mask = (groups == group)
indices[this_mask] = rs.permutation(indices[this_mask])
return y[indices]

def plot(self, nbins=10, range=None, axes=None):
"""Plot results of the permutation test.
Expand Down
3 changes: 3 additions & 0 deletions tests/test_stats.py
Expand Up @@ -19,10 +19,13 @@ def test_permutation_distance():
"""Test one way permutation test"""
covset = generate_cov(10, 5)
labels = np.array([0, 1]).repeat(5)
groups = np.array([0] * 5 + [1] * 5)
assert_raises(ValueError, PermutationDistance, mode='badmode')
# pairwise
p = PermutationDistance(100, mode='pairwise')
p.test(covset, labels)
# with group
p.test(covset, labels, groups=groups)
# t-test
p = PermutationDistance(100, mode='ttest')
p.test(covset, labels)
Expand Down

0 comments on commit 22ee36d

Please sign in to comment.