# Summary Table for Cluster Permutation?

**URL:** <https://mne.discourse.group/t/summary-table-for-cluster-permutation/8752>\
**Category:** Support & Discussions\
**Tags:** eeg, evoked\
**Created:** [May 5, 2024, 12:10pm UTC](https://mne.discourse.group/t/summary-table-for-cluster-permutation/8752 "2024-05-05T12:10:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![igsq](https://avatars.discourse-cdn.com/v4/letter/i/ac8455/32.png) [@igsq](https://mne.discourse.group/u/igsq)\
**Post date:** [May 5, 2024, 12:10pm UTC](https://mne.discourse.group/t/summary-table-for-cluster-permutation/8752/1 "2024-05-05T12:10:40Z")

</div>

MacOS 13.2.1  
MNE 1.6.0

Hello,

My question regards spatio-temporal cluster permutations for EEG data. There are two within-subject paradigms, which have both been completed by the same sample. It contains 18 subjects and one paradigm with 2 conditions and another, separate one with 3 conditions. The focus is on sensor data (ERP analysis).

For the 2 conditions, I have used the difference to run a spatio\_temporal\_cluster\_1samp\_test, following this tutorial:

> [Statistical Analysis of ERP Data — Neural Data Science in Python](https://neuraldatascience.io/7-eeg/erp_group_stats.html#mass-univariate-analyses)

(Permutation t-Test for Multiple comparisons)

Code:

```python
n_perm = 5e4

t_obs, clusters, cluster_pv, H0 = spatio_temporal_cluster_1samp_test( 
    diff, 
    adjacency=adjacency,
    n_permutations=n_perm, 
    out_type='mask',
    n_jobs=-1, 
    verbose='Info'
    )

```

In case of the 3 conditions; I have run another permutation using an F-statistic following this tutorial:

> [Spatiotemporal permutation F-test on full sensor data — MNE 1.8.0.dev32+g7a4706b07 documentation](https://mne.tools/dev/auto_tutorials/stats-sensor-space/75_cluster_ftest_spatiotemporal.html#compute-permutation-statistic)

Code:

```python
n_conditions = len(conditions)
n_observations = X1.shape[0]
dfn = n_conditions - 1
dfd = n_observations - n_conditions

# thresh
f_thresh = scipy.stats.f.ppf(1 - alpha_cluster_forming, dfn=dfn, dfd=dfd)

# cluster based permutation analysis
F_obs, clusters, p_values, H0 = spatio_temporal_cluster_test(
    [X1, X2, X3],
    n_permutations=50000,
    threshold=f_thresh,
    tail=tail,
    n_jobs=None,
    buffer_size=None,
    adjacency=adjacency,
    verbose='Info'
)

```

This all worked just fine, however I am stuck on how to get a summary output for the statistics. I am looking to have a tables of results that include respectively the t/F statistic, cluster start and end time, p values, sensors, conditions, etc per cluster. So far, I have not found a function / an example of this in the tutorials or documentation. I managed to get the F\_obs/t\_obs, clusters, p\_values, H0 into dictionaries and pandas dataframes, but that is not even close to the summary output I am looking for.

Here are examples of what I am trying to achieve, but for sensor analysis:

> [https://www.frontiersin.org/files/Articles/220342/fnhum-10-00637-HTML/image\_m/fnhum-10-00637-t002.jpg](https://www.frontiersin.org/files/Articles/220342/fnhum-10-00637-HTML/image_m/fnhum-10-00637-t002.jpg)

> [https://www.researchgate.net/publication/356181950/figure/tbl2/AS:11431281093136636@1667101992816/Summary-of-Cluster-based-Permutation-Statistics-on-Source-Activity.png](https://www.researchgate.net/publication/356181950/figure/tbl2/AS:11431281093136636@1667101992816/Summary-of-Cluster-based-Permutation-Statistics-on-Source-Activity.png)

> [https://www.frontiersin.org/files/Articles/248612/fpsyg-08-00706-HTML/image\_m/fpsyg-08-00706-t001.jpg](https://www.frontiersin.org/files/Articles/248612/fpsyg-08-00706-HTML/image_m/fpsyg-08-00706-t001.jpg)

As I am still quite new to this, I wanted to ask if anyone can help me out?

---

<div class="post-metadata">

**Author:** ![CarinaFo](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/carinafo/32/746_2.png) [@CarinaFo](https://mne.discourse.group/u/CarinaFo)\
**Post date:** [May 6, 2024, 12:39pm UTC](https://mne.discourse.group/t/summary-table-for-cluster-permutation/8752/2 "2024-05-06T12:39:17Z")

</div>

Hello,

no function creates such an output yet. So I guess your approach of creating a dataframe with the respective columns or a dictionary seems reasonable. If you share your code snippet, I can help you with further formatting. The cluster variable from the output contains the time indices for the each cluster (and frequencies or channels depending on your input data dimensions).

Best,

Carina

---

<div class="post-metadata">

**Author:** ![igsq](https://avatars.discourse-cdn.com/v4/letter/i/ac8455/32.png) [@igsq](https://mne.discourse.group/u/igsq)\
**Post date:** [May 6, 2024, 2:10pm UTC](https://mne.discourse.group/t/summary-table-for-cluster-permutation/8752/3 "2024-05-06T14:10:10Z")

</div>

Hello,

thank you for your answer.

My input data has a 18 x 615 x 32 shape, which represents observations x time x channels.

Here is how I tried to organise it so far:

```python
# first tried a dictionary 
cluster_dict = dict(T_obs=t_obs, clusters=clusters,
                    cluster_p_values=cluster_pv, H0=H0)

# then opted for a data frame
d = pd.DataFrame([k, *v] for k, v in cluster_dict.items()).T
headers = d.iloc[0]
cluster_stats = pd.DataFrame(d.values[1:], columns=headers)

```

I subsequently used the same for the second permutation with 3 conditions, however the F\_obs variable is obviously different in shape ((p[, q], n\_vertices)) compared to the t\_obs ([n\_tests] following the documentation).

Kind regards

---

<div class="post-metadata">

**Author:** ![CarinaFo](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/carinafo/32/746_2.png) [@CarinaFo](https://mne.discourse.group/u/CarinaFo)\
**Post date:** [May 13, 2024, 6:55am UTC](https://mne.discourse.group/t/summary-table-for-cluster-permutation/8752/4 "2024-05-13T06:55:10Z")

</div>

Hello,

The output should be similar according to the documentation, instead of t values you obtain f values from an f-test, but the shape of t\_obs and f\_obs should be the same.  
You can also use the [permutation\_cluster\_1samp\_test](https://mne.tools/stable/generated/mne.stats.permutation_cluster_1samp_test.html) function and the  
[permutation\_cluster\_test](https://mne.tools/stable/generated/mne.stats.permutation_cluster_test.html) function as you are using sensor data and not source data, right?

Hope this helps?

Best,

Carina
