# Permutation cluster test with paired samples

**URL:** <https://mne.discourse.group/t/permutation-cluster-test-with-paired-samples/2514>\
**Category:** Support & Discussions\
**Tags:** statistics\
**Created:** [January 19, 2021, 6:39pm UTC](https://mne.discourse.group/t/permutation-cluster-test-with-paired-samples/2514 "2021-01-19T18:39:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Silvia](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Silvia](https://mne.discourse.group/u/Silvia)\
**Post date:** [January 19, 2021, 6:39pm UTC](https://mne.discourse.group/t/permutation-cluster-test-with-paired-samples/2514/1 "2021-01-19T18:39:46Z")

</div>

Dear MNE users,

I have a question on cluster-based permutation testing. I have a dataset with 31 participants, each participant performed two tasks and I want to compare the theta power time course between these two tasks at the source level. I used the function source\_band\_induced\_power() to extract the time courses of theta from the whole brain sources.

Now, I want to compare the two tasks. According to this tutorial ([Permutation t-test on source data with spatio-temporal clustering — MNE 0.22.0 documentation](https://mne.tools/stable/auto_tutorials/stats-source-space/plot_stats_cluster_spatio_temporal.html#sphx-glr-auto-tutorials-stats-source-space-plot-stats-cluster-spatio-temporal-py)) I should compute the difference between the two conditions, and then perform a cluster-based permutation. I tried to follow this pipeline and the code runs.

However, I wonder whether this is actually comparing the two conditions in the way I am interested in. Namely, given that the input matrix X is n\_subj \* n\_timepoints \* n\_vert, I think the function permutes across time and space.

What I would want to achieve is for each permutation to randomly swap the condition to which the time\*space matrix is assigned, without affecting the dependency between time and space. I think this would be a more fair test for the differences between my two tasks.

I am not being able to implement this approach. I think I should use a stat\_fun within the permutation\_cluster\_test analogous to scipy.stats.ttest\_rel, but I am not sure how to do this and if it makes sense.

Thanks in advance for any help!  
Best,

Silvia

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [January 19, 2021, 10:29pm UTC](https://mne.discourse.group/t/permutation-cluster-test-with-paired-samples/2514/2 "2021-01-19T22:29:37Z")

</div>

> [@Silvia](#):
>
> I wonder whether this is actually comparing the two conditions in the way I am interested in. Namely, given that the input matrix X is n\_subj \* n\_timepoints \* n\_vert, I think the function permutes across time and space.

I’m pretty sure that the function is already doing what you want it to do. It does not permute across time and space; it _clusters_ across time and space, as controlled by the `adjacency` and `max_step` parameters (which together determine which times are considered temporally adjacent, and which vertices are considered spatially adjacent).

> [@Silvia](#):
>
> I think I should use a stat\_fun within the permutation\_cluster\_test analogous to scipy.stats.ttest\_rel, but I am not sure how to do this and if it makes sense.

Analyzing your data with the default `stat_fun` is already effectively the same as using `scipy.stats.ttest_rel` (which does the subtraction of condition A from condition B for you; here you’ve done the subtraction already so comparing the result against 0 using `ttest_1samp` is equivalent).

---

<div class="post-metadata">

**Author:** ![Silvia](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Silvia](https://mne.discourse.group/u/Silvia)\
**Post date:** [January 25, 2021, 8:38am UTC](https://mne.discourse.group/t/permutation-cluster-test-with-paired-samples/2514/3 "2021-01-25T08:38:31Z")

</div>

Hi Dan,

thanks a lot for your clear reply!  
I have a follow up question: what is actually being permuted? Is it the sign of the observations? (by observation I mean for each subject the difference value between the two conditions).  
I tried to figure it out in the source code but it is too advanced for me.

Thanks!  
Silvia

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [January 25, 2021, 3:48pm UTC](https://mne.discourse.group/t/permutation-cluster-test-with-paired-samples/2514/4 "2021-01-25T15:48:14Z")

</div>

yes, exactly. The permutation happens by sign-flips. FYI the relevant part of the code is around here: [mne-python/cluster\_level.py at baaf9e33f2b54f6a40454a8aa146577bde1d6f58 · mne-tools/mne-python · GitHub](https://github.com/mne-tools/mne-python/blob/baaf9e33f2b54f6a40454a8aa146577bde1d6f58/mne/stats/cluster_level.py#L698-L705)
