예제 #1
0
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)
예제 #2
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)
예제 #3
0
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)
예제 #4
0
    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),
    tail=0,
    n_permutations=5000,
    alpha=0.05,
)

# Comparing Intra-brain connectivity values between participants

# With 3/ non-parametric cluster-based permutations
# creating matrix of a priori connectivity between channels
# across space and frequencies based on their position

con_matrixTuple = stats.con_matrix(epochs=preproc_S1,
                                   freqs_mean=np.arange(7.5, 11),
                                   draw=False)

# Note that for connectivity, values are computed for
예제 #5
0
    # choosing Alpha_Low for futher analyses for example
    values_intra = alpha_low
    values_intra -= np.diag(np.diag(values_intra))
    # computing Cohens'D for further analyses for example
    C_intra = (values_intra -
               np.mean(values_intra[:])) / np.std(values_intra[:])
    # can also sample CSD values directly for statistical analyses
    result_intra.append(C_intra)


### Comparing inter-brain connectivity values to random signal
data = [np.array([values, values]), np.array([result_intra[0], result_intra[0]])]

statscondCluster = stats.statscondCluster(data=data,
                                          freqs_mean=np.arange(7.5, 11),
                                          ch_con_freq=None,
                                          tail=0,
                                          n_permutations=5000,
                                          alpha=0.05)

#Visualization of interbrain connectivity in 2D
viz.viz_2D_topomap_inter(epo1, epo2, C, threshold='auto', steps=10, lab=True)

#Visualization of interbrain connectivity in 3D
viz.viz_3D_inter(epo1, epo2, C, threshold='auto', steps=10, lab=False)