Skip to content

make it easier to specify adjacency in permutation_cluster_test #9364

Closed

Description

@drammock

I tried to do a time-frequency permutation_cluster_test over 126 channels for different observations and for two groups.
So I have 4D data (observations, times, frequencies, channels) for two groups of users but it didn't work.

adjacency = sparse.csr_matrix(np.zeros((126,126)))
sample = np.zeros((4,100,6,126))

print(sample.shape)
print(adjacency.shape)

F_obs, clusters, cluster_pv, H0 = mne.stats.permutation_cluster_test(X=[sample, sample], adjacency=adjacency)

the error raised is

ValueError: adjacency (len 126) must be of the correct size, i.e. be equal to or evenly divide the number of tests (75600). If adjacency was computed for a source space, try using the fwd["src"] or inv["src"] as some original source space vertices can be excluded during forward computation

at line 606 of "mne/stats/cluster_level.py" file.
(and 75600 is evenly dividable by 126, but "got_times" is different from "n_times" for the dimension more)

It seems like at most there can be three dimensions and not four.
I thought that with this version it was possible to do it.

Is it not?

Best,
Giovanni

Originally posted by @GiovanniGr in #7915 (comment)

Activity

  1. drammock commented on Apr 30, 2021

    @drammock
    MemberAuthor

    The problem here is that the adjacency for your data needs to have dimensions (126*6) x (126*6). After a conversation with @larsoner we're thinking the best fix would be to provide a helper function that would contstruct the larger adjacency matrix for you, by allowing you to easily specify sensible parameters like "no adjacency between frequency bins", "standard lattice connectivity along the time axis", and "here is a sparse adjacency matrix for the channels axis" and have it construct the larger adjacency matrix for you.

  2. drammock commented on Apr 30, 2021

    @drammock
    MemberAuthor

    actually @GiovanniGr it turns out we already have this function: mne.stats.combine_adjacency that will do what you need:

    This works for me:

    import numpy as np
    from scipy import sparse
    import mne
    
    freq_adjacency = sparse.csr_matrix(np.zeros((6, 6)))
    chan_adjacency = sparse.csr_matrix(np.ones((126, 126)))
    adjacency = mne.stats.combine_adjacency(freq_adjacency, chan_adjacency)
    
    sample = np.zeros((4,100,6,126))
    
    print(sample.shape)
    print(adjacency.shape)
    
    F_obs, clusters, cluster_pv, H0 = mne.stats.permutation_cluster_test(X=[sample, sample], adjacency=adjacency)

    It can also create regular lattice adjacency along a particular dimension, by passing an int giving the size of that dimension.

  3. drammock commented on Apr 30, 2021

    @drammock
    MemberAuthor

    actually, I think I can see room for improvement. re-opening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions