cluster permutation connectivity matrix

Hi all,

I am trying to apply the cluster permutation function in MNE on
intracranial data (electrodes by time points), either by using
mne.stats.permutation_cluster_test, or
mne.stats.permutation_cluster_1samp_test. In this case, I do not want to
cluster across electrodes, but I want to include this dimension in order to
correct for multiple comparisons.

My question is: how do I specify to only cluster over time, and not
electrodes? Can I do this using the connectivity matrix, and if yes, what
would a connectivity matrix look like when all electrodes do not have
neighbors? I've tried using diagonal matrices already, but I still get
clusters spanning multiple electrodes.

Thanks,
Yvonne

Hi Yvonne

I would have said that a sparse diagonal matrix should work.

can you share the code snippet you used?

Alex

Hi Alex,

Thank you for your reply.

This is my code, with two versions of a diagonal connectivity matrix (using
version 14.1 of MNE):
# Implement cluster permutation
numChan = Data.shape[1] # Data is shaped: Trials (115) x channels (217) x
timepoints (30) numpy array
#connectivity = np.diagflat( range(0,numChan), k = 0)
connectivity = np.diagflat( np.ones((1,numChan)), k = 0) # N x N diagonal
matrix with N being # of electrodes
TestData = np.swapaxes(Data, 1,2) # trials x time x space (electrodes)
T_obs, clusters, p_values, H0 =
mne.stats.permutation_cluster_1samp_test(TestData, n_permutations = 500,
tail = 0, connectivity = connectivity)

Both versions of the connectivity matrix now give me the following error:
'numpy.ndarray' object has no attribute 'tocsr'

Thanks,
Yvonne

hi yvonne,

connectivity must be a sparse matrix not a numpy array

from scipy import sparse
connectivity = sparse.eye(numChan)

HTH
Alex

I think we should clarify this is the docstring, add a check for the input
and raise an error, and maybe add an example. Wdyt? I can open a pr if that
sounds good.

Yes that would be useful.

Eric

PR merged... It'll give a more helpful error message now