ValueError: too many values to unpack (expected 2)

  • MNE version: 1.2.1
  • operating system: Ubuntu 20.04.5 LTS

Dear MNE community,

I’m trying to replicate the “Permutation t-test on source data with spatio-temporal clustering” tutorial with my own data:

https://mne.tools/stable/auto_tutorials/stats-source-space/20_cluster_1samp_spatiotemporal.html#sphx-glr-auto-tutorials-stats-source-space-20-cluster-1samp-spatiotemporal-py

In my case, instead of making a paired contrast, like in the tutorial:

X = np.abs(X)  # only magnitude
X = X[:, :, :, 0] - X[:, :, :, 1]  # make paired contrast

I’m comparing two independent groups, so I use “spatio_temporal_cluster_test” instead of “spatio_temporal_cluster_1samp_test

So I perform a cluster perm test as follows:

# Here we set a cluster forming threshold based on a p-value for
# the cluster based permutation test.
# We use a two-tailed threshold, the "1 - p_threshold" is needed
# because for two-tailed tests we must specify a positive threshold.
p_threshold = 0.05
df = X.shape[0] - 1  # degrees of freedom for the test

t_threshold = stats.distributions.f.ppf(1. - p_threshold / 2.,
                                        X.shape[0] - 1, X2.shape[0] - 1)

n_permutations = 1000  # Should be above 1000.

# Now let's actually do the clustering. This can take a long time...
print('Clustering.')
T_obs, clusters, cluster_p_values, H0 = clu = \
    spatio_temporal_cluster_test([X, X2],
                                 n_permutations=n_permutations,
                                 threshold=t_threshold,
                                 max_step=2,
                                 n_jobs=3,
                                 seed=49,
                                 buffer_size=None,
                                 adjacency=adjacency,
                                 out_type='mask',
                                 verbose=True)

However, the error message:

In [27]: runcell(27, '/home/.../3.1._Source_Estimation_ERP_Stat.py')
Traceback (most recent call last):

  File "/home/.../3.1._Source_Estimation_ERP_Stat.py", line 388, in <module>
    stc_all_cluster_vis = summarize_clusters_stc(clu,

  File "/home/.../anaconda3/envs/mne/lib/python3.10/site-packages/mne/stats/cluster_level.py", line 1515, in summarize_clusters_stc
    t_inds, v_inds = clusters[cluster_ind]

ValueError: too many values to unpack (expected 2)

is displayed to me when I run:

stc_all_cluster_vis = summarize_clusters_stc(clu,
                                             tstep=tstep,
                                             vertices=fsave_vertices,
                                             subject='fsaverage')

The spatio_temporal_cluster_test found 5 clusters, and two of them are “statistically significant”.

The variable ‘clusters’ is a list of length 5 and the entries are numpy arrays of boleans. The result of:

In [31]: clusters[0].shape

is:

Out[31]: (221, 20484)

Could anyone help me to understand what I’m doing wrong? I can provide you more information if needed. Any hint would be quite helpful

Thanks in advance,

Bruno

without looking too closely beyond your first paragraph or so, you should know that there’s a separate tutorial that already does 2-sample tests: 2 samples permutation test on source data with spatio-temporal clustering — MNE 1.3.1 documentation So I suggest starting from there rather than trying to adapt the 1-sample tutorial yourself. If after that your’e still stuck, let us know.

Thanks, for the hint!

The problem was that I was passing 'out_type=‘mask’ to the ‘spatial_cluster_test’.

I should have used 'out_type=‘indices’. Now the results are being correctly plotted.

1 Like