I am running an analysis for inter-brain synchronization (analyzing data between two EEG files, each file comes from each person).
I would like to run a permutation test. However, I have difficulty in how to randomize my epochs. Could you help me with how can I randomize the epochs from each file ?, then I calculate the inter-brain synchrony again for each permutation?
Not sure if I get your question correctly, but I think you can use something like this:
import itertools
import mne
fname = "path_to_my_epochs.fif"
epochs = mne.read_epochs(fname)
perms = itertools.permutations(range(len(epochs)))
for perm in perms:
epochs_in_permuted_order = epochs[np.asarray(perm)]
data = epochs_in_permuted_order.get_data()
# ... do something with data
Note that depending on how many epochs you have, the length of perms will be huge. In that case you may want to do something like this:
import numpy as np
import mne
fname = "path_to_my_epochs.fif"
epochs = mne.read_epochs(fname)
rng = np.random.default_rng(42) # set a random seed
n_perms = 100 # how many permutations you want
for iperm in range(n_perms):
perm = rng.permutation(len(epochs))
epochs_in_permuted_order = epochs[perm]
data = epochs_in_permuted_order.get_data()
# ... do something with data