def test_stats(epochs): """ Test stats """ # with PSD from Epochs with random values random_r1 = utils.generate_random_epoch(epochs.epo1, mu=0, sigma=0.01) random_r2 = utils.generate_random_epoch(epochs.epo2, mu=4, sigma=0.01) fmin = 10 fmax = 13 psd_tuple = analyses.pow(random_r1, fmin, fmax, n_fft=256, n_per_seg=None, epochs_average=False) psd = psd_tuple.psd statsCondTuple = stats.statsCond(psd, random_r1, 3000, 0.05, 0.05) assert statsCondTuple.T_obs.shape[0] == len(epochs.epo1.info['ch_names']) for i in range(0, len(statsCondTuple.p_values)): assert statsCondTuple.p_values[i] <= statsCondTuple.adj_p[1][i] assert statsCondTuple.T_obs_plot.shape[0] == len( epochs.epo1.info['ch_names']) psd_tuple2 = analyses.pow(random_r2, fmin, fmax, n_fft=256, n_per_seg=None, epochs_average=False) psd2 = psd_tuple2.psd freq_list = psd_tuple2.freq_list data = [psd, psd2] con_matrixTuple = stats.con_matrix(random_r1, freq_list, draw=False) statscondClusterTuple = stats.statscondCluster( data, freq_list, scipy.sparse.bsr_matrix(con_matrixTuple.ch_con_freq), tail=0, n_permutations=3000, alpha=0.05) assert statscondClusterTuple.F_obs.shape[0] == len( epochs.epo1.info['ch_names']) for i in range(0, len(statscondClusterTuple.clusters)): assert len(statscondClusterTuple.clusters[i]) < len( epochs.epo1.info['ch_names']) assert statscondClusterTuple.cluster_p_values.shape[0] == len( statscondClusterTuple.clusters) assert np.mean(statscondClusterTuple.cluster_p_values) != float(0)
def test_stats(epochs): """ Test stats """ fmin = 10 fmax = 13 psd_tuple = analyses.pow(epochs.epo1, fmin, fmax, n_fft=256, n_per_seg=None, epochs_average=False) psd = psd_tuple.psd statsCondTuple = stats.statsCond(psd, epochs.epo1, 3000, 0.05, 0.05) assert statsCondTuple.T_obs.shape[0] == len(epochs.epo1.info['ch_names']) for i in range(0, len(statsCondTuple.p_values)): assert statsCondTuple.p_values[i] <= statsCondTuple.adj_p[1][i] assert statsCondTuple.T_obs_plot.shape[0] == len( epochs.epo1.info['ch_names']) psd_tuple2 = analyses.pow(epochs.epo2, fmin, fmax, n_fft=256, n_per_seg=None, epochs_average=False) psd2 = psd_tuple2.psd freq_list = psd_tuple2.freq_list data = [psd, psd2] con_matrixTuple = stats.con_matrix(epochs.epo1, freq_list, draw=False) statscondClusterTuple = stats.statscondCluster( data, freq_list, scipy.sparse.bsr_matrix(con_matrixTuple.ch_con_freq), tail=0, n_permutations=3000, alpha=0.05) assert statscondClusterTuple.F_obs.shape[0] == len( epochs.epo1.info['ch_names']) for i in range(0, len(statscondClusterTuple.clusters)): assert len(statscondClusterTuple.clusters[i]) < len( epochs.epo1.info['ch_names']) assert statscondClusterTuple.cluster_p_values.shape[0] == len( statscondClusterTuple.clusters)
def test_stats(epochs): """ Test stats """ fmin = 10 fmax = 13 freqs_mean, PSD_welch = analyses.PSD(epochs.epo1, fmin, fmax, time_resolved=False) statsCondTuple = stats.statsCond(PSD_welch, epochs.epo1, 3000, 0.05, 0.05) assert statsCondTuple.T_obs.shape[0] == len(epochs.epo1.info['ch_names']) # TODO: add an assert in the function to be sure PSD with epochs # len(shape) = 3 # and retest with time_resolved=True for i in range(0, len(statsCondTuple.p_values)): assert statsCondTuple.p_values[i] <= statsCondTuple.adj_p[1][i] assert statsCondTuple.T_obs_plot.shape[0] == len( epochs.epo1.info['ch_names']) # test T_obs_plot with viz function _, PSD_welch2 = analyses.PSD(epochs.epo2, fmin, fmax, time_resolved=False) data = [PSD_welch, PSD_welch2] con_matrixTuple = stats.con_matrix(epochs.epo1, freqs_mean, draw=False) statscondClusterTuple = stats.statscondCluster( data, freqs_mean, scipy.sparse.bsr_matrix(con_matrixTuple.ch_con_freq), tail=0, n_permutations=3000, alpha=0.05) assert statscondClusterTuple.F_obs.shape[0] == len( epochs.epo1.info['ch_names']) for i in range(0, len(statscondClusterTuple.clusters)): assert len(statscondClusterTuple.clusters[i]) < len( epochs.epo1.info['ch_names']) assert statscondClusterTuple.cluster_p_values.shape[0] == len( statscondClusterTuple.clusters)
# of tests (variables i.e. channels), # thus PSD values are averaged in the frequency dimension psd1_mean = np.mean(psd1.psd, axis=1) psd2_mean = np.mean(psd2.psd, axis=1) X = np.array([psd1_mean, psd2_mean]) T_obs, p_values, H0 = mne.stats.permutation_t_test(X=X, n_permutations=5000, tail=0, n_jobs=1) # 2/ HyPyP parametric t test with FDR correction # based on MNE function, the same things as above are true. # FDR correction for multiple comparisons is added. statsCondTuple = stats.statsCond( data=data_psd, epochs=preproc_S1, n_permutations=5000, alpha=0.05, ) # 3/ Non-parametric cluster-based permutations # creating matrix of a priori connectivity between channels # across space and frequencies based on their position, # in the Alpha_Low band for example con_matrixTuple = stats.con_matrix(preproc_S1, freqs_mean=psd1.freq_list) ch_con_freq = con_matrixTuple.ch_con_freq # consitute two artificial groups with 2 'participant1' and 2 'participant1' data_group = [np.array([psd1.psd, psd1.psd]), np.array([psd2.psd, psd2.psd])] statscondCluster = stats.statscondCluster( data=data_group, freqs_mean=psd1.freq_list, ch_con_freq=scipy.sparse.bsr_matrix(ch_con_freq),