# Cluster Permutation Analysis with mne.stats.spatio\_temporal\_cluster\_test

**URL:** <https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071>\
**Category:** Support & Discussions\
**Tags:** eeg\
**Created:** [June 13, 2023, 7:42am UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071 "2023-06-13T07:42:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TBlefthand](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@TBlefthand](https://mne.discourse.group/u/TBlefthand)\
**Post date:** [June 13, 2023, 7:42am UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/1 "2023-06-13T07:42:40Z")

</div>

Hello its me again!

I have a rather general question regarding how to apply the spatio\_temporal\_cluster\_test correctly and how to interprete the results of it. I am just starting in the EEG field so it might be a rather simple question for the experts here.

Here is my code:

```python

# Concatenate the data across conditions
X = [condition_a_2D, condition_b_2D] # List of arrays, shape: (n_epochs, n_times, n_channels)

n_permutations = 1000 # Number of permutations for the permutation test
tail = 0 # Two-sided test
seed = 42

# Perform spatio-temporal clustering
F_obs, clusters, p_values, _ = spatio_temporal_cluster_test(X, n_permutations=n_permutations, tail=tail, seed=seed, adjacency=adjacency)

```

I have EEG data inserted for X with the dimensions 41 trials, 4401 timepoints and 64 channels. It used to be a time frequency structure with the dimensions 41, 4401, 5, 64. 5 have been the frequency bins but I averaged over them.

Now I am not sure how to correctly use the mne function. I think I also need to specify a t-test as statistics with a threshold? What condition must be put on position one and two of X? I have a control and intervention condition.

Then how to interprete the outcomes of the function?

And when I have results for one subject with the two conditions how can I analyse the two conditions over all my participants in the experiment?

Best regards,

Till

---

<div class="post-metadata">

**Author:** ![sappelhoff](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sappelhoff/32/3276_2.png) [@sappelhoff](https://mne.discourse.group/u/sappelhoff)\
**Post date:** [June 13, 2023, 2:21pm UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/2 "2023-06-13T14:21:22Z")

</div>

> [@TBlefthand](#):
>
> Now I am not sure how to correctly use the mne function. I think I also need to specify a t-test as statistics with a threshold? What condition must be put on position one and two of X? I have a control and intervention condition.

if you have just two conditions, then you could also subtract them from each other and calculate a one sample ttest against zero, see: [mne.stats.spatio\_temporal\_cluster\_1samp\_test — MNE 1.7.0.dev5+g44c787fd4 documentation](https://mne.tools/dev/generated/mne.stats.spatio_temporal_cluster_1samp_test.html)

> [@TBlefthand](#):
>
> Then how to interprete the outcomes of the function?

That’s a bit out of scope for this support forum. I suggest you read up on academic references for this (for example: [Nonparametric statistical testing of EEG- and MEG-data - PubMed](https://pubmed.ncbi.nlm.nih.gov/17517438/)) or look at the MNE-Python examples, for example: [Permutation t-test on source data with spatio-temporal clustering — MNE 1.7.0.dev5+g44c787fd4 documentation](https://mne.tools/dev/auto_tutorials/stats-source-space/20_cluster_1samp_spatiotemporal.html#sphx-glr-auto-tutorials-stats-source-space-20-cluster-1samp-spatiotemporal-py)

> [@TBlefthand](#):
>
> And when I have results for one subject with the two conditions how can I analyse the two conditions over all my participants in the experiment?

For that you take the analysis to the “second level” → instead of analyzing the epochs in a participant, you average over epochs in each participant, and then analyze over participants. That is the `n_epochs` becomes `n_participants`.

---

<div class="post-metadata">

**Author:** ![TBlefthand](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@TBlefthand](https://mne.discourse.group/u/TBlefthand)\
**Post date:** [June 14, 2023, 4:02pm UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/3 "2023-06-14T16:02:09Z")

</div>

Hello Stefan,

thank you for your response. I am now trying to use the 1 samp test function you provided. I summarized the participants for the second level and want to calculate the difference between the two conditions resulting in a 20 participants x 64 channels x 5 frequencies x 4401 timepoints.

I get how the theory of the permutations works for 2 conditions as the input. How is it done with this one difference condition?

Best regards,

Till

---

<div class="post-metadata">

**Author:** ![sappelhoff](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sappelhoff/32/3276_2.png) [@sappelhoff](https://mne.discourse.group/u/sappelhoff)\
**Post date:** [June 14, 2023, 9:12pm UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/4 "2023-06-14T21:12:31Z")

</div>

> [@TBlefthand](#):
>
> I get how the theory of the permutations works for 2 conditions as the input. How is it done with this one difference condition?

- Assuming that this is a within-subjects design, each participant has contributed conditions A and B.
- You are supplying their difference to a test against zero: `diff = A-B`
- The permutation is about changing the labels (A to B and B to A, or leaving them as they are; randomly) within participants
- This is the same as changing the sign of `diff` for each participant

---

<div class="post-metadata">

**Author:** ![Maximilian](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@Maximilian](https://mne.discourse.group/u/Maximilian)\
**Post date:** [October 9, 2024, 2:01am UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/5 "2024-10-09T02:01:10Z")

</div>

Hi, Till.

I meet a question about the function ‘spatio\_temporal-cluster\_test’. I used the EEG data, so the ‘adjacency’ was calculated by Delaunay triangulations. it means that if at least three electrodes near an electrode must satisfy clustering significance to prove that the electrode is significant? I can not find the function ‘spatio\_temporal-cluster\_test’ where the adjacency explain how many electrodes near an electrode must satisfy clustering significance.  
I will appreciate it if you could reply me.

Best regards,

Max

---

<div class="post-metadata">

**Author:** ![Maximilian](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@Maximilian](https://mne.discourse.group/u/Maximilian)\
**Post date:** [October 9, 2024, 2:10am UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/6 "2024-10-09T02:10:12Z")

</div>

Hello Stefan,

May I ask you a question about the function ‘spatio\_temporal-cluster\_test’?

I want to know where the adjacency explain how many electrodes near an electrode must satisfy clustering significance in the function ‘spatio\_temporal-cluster\_test’. But i can not find it from the code in ‘spatio\_temporal-cluster\_test’.

Best regards,

Max

---

<div class="post-metadata">

**Author:** ![sappelhoff](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sappelhoff/32/3276_2.png) [@sappelhoff](https://mne.discourse.group/u/sappelhoff)\
**Post date:** [October 9, 2024, 7:32am UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/7 "2024-10-09T07:32:41Z")

</div>

Hey @Maximilian, I think this thread may answer your question: [[ENH] Spatio-temporal cluster permutation testing: Define minimum "nodes" to define a cluster · Issue #10604 · mne-tools/mne-python · GitHub](https://github.com/mne-tools/mne-python/issues/10604)

---

<div class="post-metadata">

**Author:** ![Maximilian](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@Maximilian](https://mne.discourse.group/u/Maximilian)\
**Post date:** [October 9, 2024, 9:24am UTC](https://mne.discourse.group/t/cluster-permutation-analysis-with-mne-stats-spatio-temporal-cluster-test/7071/8 "2024-10-09T09:24:25Z")

</div>

Thank you for help!  
I look through this thread and conclude it in the following, are these conclusion right?

(1) In FieldTrip, it just define the minimum number of neighborhood channels (spatial dimension), without the limitation on the temporal dimension.

(2) In the assumption, any neighboring relationship (2 timepoints, or 2 channels) makes up a cluster. There was an official explanation/code to verify this idea? (I tried my best to find it, but i fail)
