Permutation statistic for time-frequencies

Dear mne team,

I tried to replicate the following example " Permutation statistic for time-frequencies"

I met a problem when I ran:

cluster_stats = spatio_temporal_cluster_test(X, n_permutations=1000, threshold=tfr_threshold, tail=1, n_jobs=1,
    buffer_size=None, adjacency=tfr_adjacency)

With the following error message " n_samples, n_times, n_vertices = X[0].shape
ValueError: too many values to unpack (expected 3)"

Could you help me to resolve this issue ?

Thank in advance

W

the code:

#Permutation statistic for time-frequencies
decim = 4
freqs = np.arange(7, 30, 3)  # define frequencies of interest
n_cycles = freqs / freqs[0]

epochs_power = list()
for condition in [Sound_3_R1_R04[k] for k in ('3001', '3004')]:
    this_tfr = tfr_morlet(condition, freqs, n_cycles=n_cycles,
                          decim=decim, average=False, return_itc=False)
    this_tfr.apply_baseline(mode='ratio', baseline=(None, 0))
    epochs_power.append(this_tfr.data)

# transpose again to (epochs, frequencies, times, channels)
X = [np.transpose(x, (0, 2, 3, 1)) for x in epochs_power]

adjacency, ch_names = find_ch_adjacency(Sound_3_R1_R04.info, ch_type='eeg')

# our data at each observation is of shape frequencies × times × channels
tfr_adjacency = combine_adjacency(
    len(freqs), len(this_tfr.times), adjacency)

# This time we don't calculate a threshold based on the F distribution.
# We might as well select an arbitrary threshold for cluster forming
tfr_threshold = 15.0

# run cluster based permutation analysis
cluster_stats = spatio_temporal_cluster_test(X, n_permutations=1000, threshold=tfr_threshold, tail=1, n_jobs=1,
    buffer_size=None, adjacency=tfr_adjacency)

What’s the shape of X?

Hello Richard,

It is an array

[array([[[[3.87174954e+00, 5.79925045e+00, 3.97458272e+00, ...,
           5.28951640e+00, 1.49631679e+00, 3.16989026e+00],
          [3.26386951e+00, 4.14831675e+00, 3.07370200e+00, ...,
           3.93163167e+00, 1.22349700e+00, 2.98102509e+00],
          [2.31075079e+00, 2.07961910e+00, 1.94320875e+00, ...,
           2.09304452e+00, 8.81059845e-01, 2.39090100e+00],
          ...,
          [3.46560964e+00, etc....

What I meant is, could you please share the output of X.shape?

np.shape(X)
C:\Users\PycharmProjects\PyCharm\bin\lib\site-packages\numpy\core_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify ‘dtype=object’ when creating the ndarray
return array(a, dtype, copy=False, order=order)
Out[9]: (2,)

Ok, something seems to be very off with this X … Any idea why its elements have different dimensions / lengths?

Edit
Can you share the output of

print(X[0].shape)
print(X[1].shape)

In [4]: print(X[0].shape)
…: print(X[1].shape)
(1052, 8, 338, 32)
(1047, 8, 338, 32)

after equalized events I have the same error message:

print(X[0].shape)
print(X[1].shape)
(1047, 8, 338, 32)
(1047, 8, 338, 32)

what version of mne are you using?

can you report what mne.sys_info() says?

Alex

0.22.00

mne.sys_info()
Platform: Windows-10-10.0.19041-SP0
Python: 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
Executable: C:\Users\PycharmProjects\PyCharm\bin\Scripts\python.exe
CPU: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel: 8 cores
Memory: Unavailable (requires “psutil” package)
mne: 0.22.0
numpy: 1.19.4 {blas=D:\a\1\s\numpy\build\openblas_info, lapack=D:\a\1\s\numpy\build\openblas_lapack_info}
scipy: 1.5.4
matplotlib: 3.3.3 {backend=TkAgg}
sklearn: 0.23.2
numba: Not found
nibabel: Not found
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: 1.1.5
mayavi: Not found
pyvista: Not found
vtk: Not found

Oh this is very old, can you update to 1.0.3?

Okay sorry, it is the problem. I don’t understand why I have this old version (maybe because I unstall pycharm 2 days ago)

Sorry for that and thank a lot.

W

So is it working with a newer version?

Re-Richard,

Yes I can run the permutation test.

Thanks.

W

1 Like