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) with pytest.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) # f-test p = PermutationDistance(100, mode='ftest') p.test(covset, labels) # with custom estimator p = PermutationDistance(10, mode='pairwise', estimator=CSP(2, log=False)) p.test(covset, labels) # unique perms p = PermutationDistance(1000) p.test(covset, labels) p.plot(nbins=2)
def test_permutation_pairwise_plot(get_covmats, get_labels): """Test one way permutation with estimator""" n_matrices, n_channels, n_classes = 6, 3, 2 covmats = get_covmats(n_matrices, n_channels) labels = get_labels(n_matrices, n_classes) p = PermutationDistance(100, mode="pairwise") p.test(covmats, labels) p.plot(nbins=2)
def test_permutation_distance(): """Test one way permutation test""" covset = generate_cov(10, 5) labels = np.array([0, 1]).repeat(5) assert_raises(ValueError, PermutationDistance, mode='badmode') # pairwise p = PermutationDistance(100, mode='pairwise') p.test(covset, labels) # t-test p = PermutationDistance(100, mode='ttest') p.test(covset, labels) # f-test p = PermutationDistance(100, mode='ftest') p.test(covset, labels) # with custom estimator p = PermutationDistance(10, mode='pairwise', estimator=CSP(2, log=False)) p.test(covset, labels) # unique perms p = PermutationDistance(1000) p.test(covset, labels) p.plot(nbins=2)
# compute covariance matrices covmats = Covariances().fit_transform(epochs_data) n_perms = 500 ############################################################################### # Pairwise distance based permutation test ############################################################################### t_init = time() p_test = PermutationDistance(n_perms, metric='riemann', mode='pairwise') p, F = p_test.test(covmats, labels) duration = time() - t_init fig, axes = plt.subplots(1, 1, figsize=[6, 3], sharey=True) p_test.plot(nbins=10, axes=axes) plt.title('Pairwise distance - %.2f sec.' % duration) print('p-value: %.3f' % p) sns.despine() plt.tight_layout() plt.show() ############################################################################### # t-test distance based permutation test ############################################################################### t_init = time() p_test = PermutationDistance(n_perms, metric='riemann', mode='ttest') p, F = p_test.test(covmats, labels) duration = time() - t_init