statistics for temporal generation decoding matrix

  • MNE version: e.g. 0.24.0
  • operating system: Ubuntu 18.04

Hello MNE users,
I am attempting to do statistics for the results of temporal generation decoding matrix across subjects, while computing the p_values using the function “mne.stats.spatio_temporal_cluster_1samp_test(…)”, I alway get the KERNAL KILLED ERROR!! despite i changed the n_permutations into 200; How can I fix this error? Or was my method approprite to the 2-D array (1693, 1693) statistics across subjects(n_subject=15)? Here is my code:

import os
import os.path as op
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from scipy.stats import wilcoxon
# import seaborn as sns
# sns.set_style("white")
# sns.set_context('paper')
import pickle

import mne
from mne.parallel import parallel_func
from mne.stats import (ttest_1samp_no_p, bonferroni_correction, fdr_correction,
                       permutation_t_test, permutation_cluster_1samp_test,


# define functions
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=200, n_jobs=-1, verbose=False)

    # format p_values to get same dimensionality as X
    p_values_ = np.one_like(X[0]).T
    for cluster, pval in zip(clusters, p_values):
        p_values_[cluster.T] = pval

        return np.squeeze(p_values_).T

# load data
condition = {'cond0':['LFF2-LHF2', 'RFF2-RHF2', 'LHH2-LFH2', 'RHH2-RFH2'],
             'cond1':['LFF4-LHF4', 'RFF4-RHF4', 'LHH4-LFH4', 'RHH4-RFH4'],
             'cond2':['LFF6-LHF6', 'RFF6-RHF6', 'LHH6-LFH6', 'RHH6-RFH6']}

dest_dir = 'allsubjs_decoding_temporal_generation/prime_contrast'
times = pd.read_csv(op.join(dest_dir, 'epochs_times.csv'))
times = times.to_numpy()

chance = .5
# N = len(condition)
for k in range(N):
    key = 'cond%d' %k
    cond = condition[key]
    for con in cond:
        data = list()
        for sub in range(1, 11):
            subject  = 'S%02d' %sub
            filename = '%s decoding temporal generation %s.csv' %(subject, con)    
            data_dir = op.join(subject, 'Decoding_temporal_generation/prime_contrast')
            df = pd.read_csv(op.join(data_dir, filename))
            df = df.iloc[:, 1:1694]

        p_values = stats(np.array(data)-chance)

In my code, the data shape is (15, 1693,1693)

Here is the error pages:

Thank you very much, and best wishes,

Before digging into the clustering stuff, does your stat_fun already produce a reasonable result for a plain ttest_1samp? Like if you plot the t values they are reasonable (most around zero, some for t > 0 have t values around 2-10?

Once this sanity check makes sense, then I’d dig into the clustering function. For this I actually wouldn’t use the spatio-temporal variant, but actually just the plain 1samp test. Your temporal generalization matrices have a lattice structure (left-right and up-down are “adjacent”) and it should in theory work more quickly.

I would also use out_type='indices' to reduce memory consumption

Thanks for your reply.

does your stat_fun already produce a reasonable result for a plain ttest_1samp?

yes, the stat_fun is work and reasonable for a plain ttest_1samp.

BTW, how can I do the plain 1samp test for 1693*1693 across 15 subjects?

If your array X is shape (15, 1693, 1693) you can just do scipy.stats.ttest_1samp(X, 0, axis=0) (which is the default axis anyway)