# Data for permutation cluster 1samp test

**URL:** <https://mne.discourse.group/t/data-for-permutation-cluster-1samp-test/2751>\
**Category:** Support & Discussions\
**Tags:** eeg, statistics\
**Created:** [February 25, 2021, 3:19pm UTC](https://mne.discourse.group/t/data-for-permutation-cluster-1samp-test/2751 "2021-02-25T15:19:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmmansur](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/bmmansur/32/142_2.png) [@bmmansur](https://mne.discourse.group/u/bmmansur)\
**Post date:** [February 25, 2021, 3:19pm UTC](https://mne.discourse.group/t/data-for-permutation-cluster-1samp-test/2751/1 "2021-02-25T15:19:58Z")

</div>

Dear MNE community,

I have data from 40 subjs collected in three different sessions. I want to check for differences in those sessions regarding the time-frequency analysis (morlet waves) and the ERPs using the non-parametric cluster-level test: ‘mne.stats.permutation\_cluster\_1samp\_test()’.

This function takes an array ‘X’ as input and I would like to prepare my data to fit in this function and I don’t know how to save it properly.

I’m considering preparing a for loop that, in every iteration, preprocesses data from one subject, and then saves it as a fif file. I’ll repeat it for every session.

Here is one example of how I save data from session 1, subj 1:

For ERPs:

```python
# Obtain evoked data from Epochs

evoked = epochs.average()
# Save it
evoked.save(".../session_1/p01_1_Evoked-ave.fif")

```

For TFRs:

```python
# Obtain TFRs data from Epochs

freqs = list(range(3, 38))
tfr_evoked = tfr_morlet(epochs_Tfr['OGT'], freqs, 6, return_itc=False, n_jobs=8)

tfr_evoked.save(".../session_1_Tfr/p01_1_Tfr-ave.fif")

```

So after saving all files in its corresponding folders, e.g. session\_1; session\_2 (for ERPs); session\_1\_Tfr, session\_2\_Tfr (for TFRs)… can I use the function ‘read\_evoked’ to get the saved data from the fif files and then save them as an array and then use it as input for the function ‘spatio\_temporal\_cluster\_1samp\_test’? How can I save this array? Would it work for both ERP and TFR data? At last but not least. Is there a standard way of performing group level analysis in MNE? Special functions that analyse data from all subjects and sessions, without having to use a for loop?

I’ll be thankful for any feedback

Best regards,

Bruno

- MNE-Python version: 0.22.0
- operating system: Ubuntu 20.04.2 LTS

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [February 25, 2021, 5:49pm UTC](https://mne.discourse.group/t/data-for-permutation-cluster-1samp-test/2751/2 "2021-02-25T17:49:29Z")

</div>

> [@bmmansur](#):
>
> can I use the function ‘read\_evoked’ to get the saved data from the fif files and then save them as an array and then use it as input for the function ‘spatio\_temporal\_cluster\_1samp\_test’?

The function is called `mne.read_evokeds()`. You can retrieve the data via `evoked.data`:

```python
evoked = mne.read_evokeds(fname)
data = evoked.data

```

You would do this for all your participants and store the data somewhere:

```python
all_data = []
for participant in participants:
    fname = ...
    evoked = mne.read_evokeds(fname)
    all_data.append(evoked.data)

```

Then, you can probably use `np.stack()` to create an array of the desired shape (note that I haven’t actually tested this, but in principle it should work):

```python
import numpy as np

X = np.stack(all_data, axis=0)

# check the dimensions
print(X.shape)

```

The resulting array can be saved via [`np.save()`](https://numpy.org/doc/stable/reference/generated/numpy.save.html).

---

<div class="post-metadata">

**Author:** ![bmmansur](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/bmmansur/32/142_2.png) [@bmmansur](https://mne.discourse.group/u/bmmansur)\
**Post date:** [February 26, 2021, 12:19pm UTC](https://mne.discourse.group/t/data-for-permutation-cluster-1samp-test/2751/3 "2021-02-26T12:19:35Z")

</div>

I’m implementing the solution as you said.

Thanks a lot for the answer! It was really helpful.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [August 11, 2021, 1:38pm UTC](https://mne.discourse.group/t/data-for-permutation-cluster-1samp-test/2751/5 "2021-08-11T13:38:50Z")

</div>

Hello @CarinaFo, please open a new topic for new questions. You can include references to related postings. Thanks!
