# cluster permutation connectivity matrix

**URL:** <https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [September 19, 2017, 1:17am UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313 "2017-09-19T01:17:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 19, 2017, 1:17am UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313/1 "2017-09-19T01:17:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 19, 2017, 8:02am UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313/2 "2017-09-19T08:02:33Z")

</div>

Hi Yvonne

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

can you share the code snippet you used?

Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 20, 2017, 8:00pm UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313/3 "2017-09-20T20:00:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 22, 2017, 11:42am UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313/4 "2017-09-22T11:42:33Z")

</div>

hi yvonne,

connectivity must be a sparse matrix not a numpy array

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

HTH  
Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 22, 2017, 2:45pm UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313/5 "2017-09-22T14:45:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 22, 2017, 2:48pm UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313/6 "2017-09-22T14:48:02Z")

</div>

Yes that would be useful.

Eric

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 23, 2017, 10:06am UTC](https://mne.discourse.group/t/cluster-permutation-connectivity-matrix/1313/7 "2017-09-23T10:06:32Z")

</div>

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