How to define adjacency in cluster tests?

Hello,

My question follows the previous post link.

I am using the code kindly shared by @kingjr to test significance in temporal generalization plots (please see below)

My questions are:

  • When adjacency is set to ‘None’ - in spatio_temporal_cluster_1samp_test - how are clusters defined?
  • Would it be beneficial/possible to create an adjacency matrix of time x time proximity?

Many thanks in advance!

Ana P

def stats(X):
    """Statistical test applied across subjects"""
    # check input
    X = np.array(X)
    X = X[:, :, None] if X.ndim == 2 else X
    
    # stats function report p_value for each cluster
    T_obs_, clusters, p_values, _ = spatio_temporal_cluster_1samp_test(
        X, out_type='mask', n_permutations=2**12, n_jobs=-1, verbose=False)
    
    # format p_values to get same dimensionality as X
    p_values_ = np.ones_like(X[0]).T
    for cluster, pval in zip(clusters, p_values):
        p_values_[cluster.T] = pval

    return np.squeeze(p_values_).T

The docstring says

If None, a regular lattice adjacency is assumed, connecting each spatial location to its neighbor(s) along the last dimension of X.

Here “regular lattice” means a location is considered adjacent to whatever two locations come immediately before and after it in the input array X. This is usually not what you want with that function, because it expects the last dimension to be sensor / vertex, which can’t be arranged in a simple straight line like time points or frequency bins can.

This other question has more detailed answers that might be useful: Cluster-based permutation on Spatio-spectral data - #3 by drammock

In spatio_temporal_cluster_1samp_test temporal adjacency is handled by the max_step parameter. There is no need to compute an adjacency matrix for time.

1 Like