# Cluster-based permutation analysis for two-way repeated measures of spatio-temporo-frequential data

**URL:** <https://mne.discourse.group/t/cluster-based-permutation-analysis-for-two-way-repeated-measures-of-spatio-temporo-frequential-data/4566>\
**Category:** Support & Discussions\
**Tags:** time-frequency, eeg, epochs\
**Created:** [March 16, 2022, 3:45pm UTC](https://mne.discourse.group/t/cluster-based-permutation-analysis-for-two-way-repeated-measures-of-spatio-temporo-frequential-data/4566 "2022-03-16T15:45:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BSomon](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/bsomon/32/1025_2.png) [@BSomon](https://mne.discourse.group/u/BSomon)\
**Post date:** [March 16, 2022, 3:45pm UTC](https://mne.discourse.group/t/cluster-based-permutation-analysis-for-two-way-repeated-measures-of-spatio-temporo-frequential-data/4566/1 "2022-03-16T15:45:17Z")

</div>

Hello MNE community,

First of all, I am a former EEGLAB user moving slowly towards MNE-Python (yay!). I have tried searching for this issue into the (very complete) docs, github issues, etc. but haven’t been able to find an answer to my question. @larsoner told me to come here and ask for your help!

I have been struggling with a time-frequency analysis that I would like to perform: cluster-based permutation test with a **two-way repeated** measures design on **spatial and**  **time-frequency** data.  
I have found a way to perform spatio-temporo-frequential cluster-based permutation tests on one way dependent samples, on two independent groups and two-way repeated measures on spatio-temporal (thus spatio-frequential) or temporo-frequential data. But not two-way repeated measures on spatio-temporo-frequential data.  
As an example, my data shape, that I would like as input of the permutation test is (4 x 29 x 1001 x 94 x 64), i.e. (n\_conditions [2-by-2], n\_participants, n\_times, n\_freqs, n\_chans).

I have tried adapting code, but my (too) basic knowledge on MNE-Python istaking me nowhere…

Does anyone know whether this type of analysis is feasible on MNE-Python? If so which function would be the best fit?

Thank in advance for your help.

Best,  
Bertille

---

<div class="post-metadata">

**Author:** ![larsoner](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/larsoner/32/3_2.png) [@larsoner](https://mne.discourse.group/u/larsoner)\
**Post date:** [March 17, 2022, 2:35pm UTC](https://mne.discourse.group/t/cluster-based-permutation-analysis-for-two-way-repeated-measures-of-spatio-temporo-frequential-data/4566/2 "2022-03-17T14:35:55Z")

</div>

The within-subjects / repeated-measures code requires that you give it something of shape `(n_subjects, ...)` where the `...` are the spatio(-temporal) dimensions you want to cluster over. Thinking about a 2-way rmANOVA, there are presumably 3 effects of interest (though you could choose a subset if you wanted):

1. Main effect of A
2. Main effect of B
3. Interaction of A and B

To test the first one, given your `data` of shape `(4, 29, 10001, 94, 64)`, let’s think about reshaping this to a `data2` of shape `(2, 2, 29, ...)` as `A, B, subjects, <clustering dims>`. For the main effect of A, you can pass the clustering function `np.mean(data2[1] - data2[0], axis=0)` (and use the default `ttest_1samp_no_p` on it), which will have shape `(29, ...)` as required by our clustering functions. For the main effect of B, you can pass `np.mean(data2[:, 1] - data2[:, 0], axis=0)`. For the interaction term, you can pass `(data2[0, 0] + data2[1, 1]) / 2 - (data2[1, 0] + data2[0, 1]) / 2)`. I’m not 100% sure it’s valid to run these three tests separately instead of jointly – and even if it is, you might in principle need another multiple comparisons correction for doing 3 tests like this – but it will at least give you an idea for your data.

Separately there is an issue about how to properly construct your `adjacency` in this case, but hopefully our API docs and existing tutorials might help you figure that part out?

Also, it might be worth looking into [GitHub - john-veillette/mne-ari: All-resolutions Inference for M/EEG in Python](https://github.com/john-veillette/mne-ari) to see if it’s useful for your problem!
