Data for permutation cluster 1samp test

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:

# Obtain evoked data from Epochs

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

For TFRs:

# 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)".../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,


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

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

evoked = mne.read_evokeds(fname)
data =

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

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

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):

import numpy as np

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

# check the dimensions

The resulting array can be saved via

1 Like

I’m implementing the solution as you said.

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

1 Like

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