Example #1
0
def plot_synchronies(data_cluster):
    #% all rep together
    data_diff = data_cluster.query('type == "diff"')
    data_same = data_cluster.query('type == "same"')

    results_mwu = pg.mwu(data_same['distance'].values,
                         data_diff['distance'].values, 'greater')
    p_val = results_mwu['p-val'][0]

    d = pg.compute_effsize(data_same['distance'],
                           data_diff['distance'],
                           eftype='cohen')

    plt.hist(data_diff['distance'].values, density=True, color='r', alpha=0.25)
    plt.hist(data_same['distance'].values, density=True, color='g', alpha=0.25)

    plt.grid()

    ca = plt.gca()
    x_min, x_max = ca.get_xlim()
    x = x_min + 0.5 * (x_max - x_min)

    y_min, y_max = ca.get_ylim()
    y = y_min + 0.85 * (y_max - y_min)

    if p_val < 0.05:
        plt.text(x,
                 y,
                 'p = {:.3f}, d = {:.3f}'.format(p_val, d),
                 ha='center',
                 fontweight='bold')
    else:
        plt.text(x, y, 'p = {:.3f}, d = {:.3f}'.format(p_val, d), ha='center')
Example #2
0
def calculate_cohens_d(es, fr):
    feature_values = {}
    for feature in es:
        feature_values[feature] = pn.compute_effsize(fr[feature],
                                                     es[feature],
                                                     eftype='cohen')

    return feature_values
def get_d_p(data_cluster):

    data_diff = data_cluster.query('type == "SEP"')
    data_same = data_cluster.query('type == "TOG"')

    same_boot = bootstrap(data_same['distance'].values)
    diff_boot = bootstrap(data_diff['distance'].values)

    results_mwu = pg.mwu(same_boot, diff_boot, 'greater')
    p_val = results_mwu['p-val'][0]

    d = pg.compute_effsize(same_boot, diff_boot, eftype='cohen')

    return (d, p_val)
Example #4
0
    female_data_all_atlas.append(
        female_residual
    )  #female_data_all_atlas stores the residuals for females for all atlas column wise

    t_value, p_value = scipy.stats.ranksums(
        np.arctanh(male_residual),
        np.arctanh(female_residual))  #two tailed t test for corr(eFC, eSC)
    #t_value, p_value = scipy.stats.ranksums(male_residual, female_residual) #for coupling strength

    p_val.append(
        p_value
    )  #p_val is a list that stores the p value for residuals for all atlas
    #eff_size.append(pg.compute_effsize(male_residual, female_residual, eftype = 'hedges')) # for coupling strength
    eff_size.append(
        pg.compute_effsize(np.arctanh(male_residual),
                           np.arctanh(female_residual),
                           eftype='hedges')
    )  #eff_size is a list that stores the effect size for residuals for all atlas
r""""
plt.rcParams['font.size'] = '20'
plt.figure(figsize = (16, 8))
boxprops = {'linewidth': 2}
whiskerprops = {'linewidth': 2}
capprops = {'linewidth': 2}

male_plots = plt.boxplot(np.array(male_data_all_atlas).transpose(), positions = np.array(range(l))*2 - 0.3, boxprops = boxprops, whiskerprops = whiskerprops, capprops = capprops) #the ones after regression
female_plots = plt.boxplot(np.array(female_data_all_atlas).transpose(), positions = np.array(range(l))*2 + 0.3, boxprops = boxprops, whiskerprops = whiskerprops, capprops = capprops) #the ones after regression

male_data_br = pd.read_csv(r"E:\Shraddha\Data\male_data_sfc_efc_struc_fit_lc_br.csv", header = None).values #loading the ones before reg
female_data_br = pd.read_csv(r"E:\Shraddha\Data\female_data_sfc_efc_struc_fit_lc_br.csv", header = None).values #loading the ones before reg
Example #5
0
    ####...end of MLR...####

    residual = np.tanh(residual)  #inverse fisher z transform
    corr_efc_esc_male, corr_efc_esc_female = categorise_male_female(
        residual
    )  #replace 'residual' with corr_efc_esc_list if you do not want to regress anything

    male_data_all_atlas.append(corr_efc_esc_male)
    female_data_all_atlas.append(corr_efc_esc_female)

    t_value, p_value = scipy.stats.ranksums(
        np.arctanh(corr_efc_esc_male),
        np.arctanh(corr_efc_esc_female))  #two tailed t test for corr(eFC, eSC)
    p_val.append(p_value)
    eff_size.append(
        pg.compute_effsize(np.arctanh(corr_efc_esc_male),
                           np.arctanh(corr_efc_esc_female)))
r"""
print('P value: ', p_val)
print('Effect size:', eff_size)

plt.plot(atlas, eff_size, marker = '.', markersize = 20, label = 'Effect size')
plt.plot(atlas, p_val, marker = '.', markersize = 20, label = 'Significance - p value')
plt.xlabel('Atlas')
plt.ylabel('Effect size (or) Significance')
plt.title('Effect size vs Atlas for Corr(eFC, eSC)')
plt.legend()
plt.show()

eff_size_p_val_arr = np.zeros([l, 2])
eff_size_p_val_arr[:, 0] = eff_size
eff_size_p_val_arr[:, 1] = p_val
    DATA_scat.query('summary_state2=="State 2"')["value"].reset_index(
        drop=True))
print(
    stats.ttest_rel(
        DATA_scat.query('summary_state2=="State 1"')["value"],
        DATA_scat.query('summary_state2=="State 2"')["value"]), d)

d_VTC = CalculateEffect(
    DATA_scat_VTC.query('variable=="State 1"')["value"].reset_index(drop=True),
    DATA_scat_VTC.query('variable=="State 2"')["value"].reset_index(drop=True))
print(
    stats.ttest_rel(
        DATA_scat_VTC.query('variable=="State 1"')["value"],
        DATA_scat_VTC.query('variable=="State 2"')["value"]), d_VTC)
pg.compute_effsize(
    DATA_scat_VTC.query('variable=="State 1"')["value"].reset_index(drop=True),
    DATA_scat_VTC.query('variable=="State 2"')["value"].reset_index(drop=True))

d_RT = CalculateEffect(
    DATA_scat_RT.query('variable=="State 1"')["value"].reset_index(drop=True),
    DATA_scat_RT.query('variable=="State 2"')["value"].reset_index(drop=True))
print(
    stats.ttest_rel(
        DATA_scat_RT.query('variable=="State 1"')["value"],
        DATA_scat_RT.query('variable=="State 2"')["value"]), d_RT)

d_dprime = CalculateEffect(
    DATA_scat_dprime.query('variable=="State 1"')["value"].reset_index(
        drop=True),
    DATA_scat_dprime.query('variable=="State 2"')["value"].reset_index(
        drop=True))
Example #7
0
    residual = Y - Y_hat

    #resdiual = np.tanh(residual)

    #########.....end of MLR....#########
    """

    shan_entr_eFC_male, shan_entr_eFC_female = categorise_male_female(
        shan_entr_eFC)
    shan_entr_eFC_male_all_atlas[:, i] = np.array(shan_entr_eFC_male)
    shan_entr_eFC_female_all_atlas[:, i] = np.array(shan_entr_eFC_female)
    t_value1, p_value1 = scipy.stats.ranksums(shan_entr_eFC_male,
                                              shan_entr_eFC_female)
    eff_size_shan_entr_eFC.append(
        pg.compute_effsize(
            shan_entr_eFC_male, shan_entr_eFC_female,
            eftype='hedges'))  #effect size for coupling strength
    p_val_shan_entr_eFC.append(p_value1)

np.savetxt(
    r"D:\Shraddha\Data\male_data_shan_entr_efc_br.csv",
    shan_entr_eFC_male_all_atlas,
    delimiter=',')  #this storage is for the grey plots in the background
np.savetxt(
    r"D:\Shraddha\Data\female_data_shan_entr_efc_br.csv",
    shan_entr_eFC_female_all_atlas,
    delimiter=',')  #this storage is for the grey plots in the background

l = len(atlas)
plt.rcParams['font.size'] = '20'
plt.figure(figsize=(16, 8))
        index = sub_num_list_phen.index(sub_num_list_351_ordered[i])
        gen = gender_list[index]
        if (gen == 'M'):
            return_male.append(l1[i])
        if (gen == 'F'):
            return_female.append(l1[i])
    return return_male, return_female


male_sfc_efc_list, female_sfc_efc_list = male_female_classify(
    avg_corr_list_fc_351)
male_sfc_esc_list, female_sfc_esc_list = male_female_classify(
    avg_corr_list_sc_351)

t, p = scipy.stats.ttest_ind(male_sfc_esc_list, female_sfc_esc_list)
eff_size = pingouin.compute_effsize(male_sfc_esc_list, female_sfc_esc_list)
#print("t = ", t)
#print("p = ", p)
#print("Effect size = ", eff_size)
r"""
fc_data = [male_sfc_efc_list, female_sfc_efc_list]
sc_data = [male_sfc_esc_list, female_sfc_esc_list]
fig, ax = plt.subplots(nrows = 1, ncols = 2)
ax[0].boxplot(fc_data)
ax[0].set_xticklabels(['Male','Female'])
ax[0].set_ylabel('Best fit correlation between sFC and eFC - 365 subjects')
ax[0].set_title('FC')
ax[1].boxplot(sc_data)
ax[1].set_xticklabels(['Male','Female'])
ax[1].set_ylabel('Best fit correlation between sFC and eSC')
ax[1].set_title('SC')
        index = sub_num_list_phen.index(sub_num_list_old[i])
        gen = gender_list[index]
        if (gen == 'M'):
            return_list1.append(x[i])
        if (gen == 'F'):
            return_list2.append(x[i])
    return return_list1, return_list2


avg_male_sc_list, avg_female_sc_list = categorise_male_female(
    avg_corr_sfc_esc_list)
#print(avg_female_sc_list)
t, p = scipy.stats.ttest_ind(avg_male_sc_list, avg_female_sc_list)
#print("t value: ", t)
#print("p value: ", p)
eff_size = pingouin.compute_effsize(avg_male_sc_list, avg_female_sc_list)
#print(eff_size)
#print(avg_female_fc_list)
#avg_male_sc_list, avg_female_sc_list = categorise_male_female(avg_corr_sfc_esc_list)

#print(max_corr_list_sc)
#print(corr_sfc_esc_list)
#male_fc_list, female_fc_list = categorise_male_female(corr_sfc_efc_list)
#print(female_fc_list)
#male_sc_list, female_sc_list = categorise_male_female(corr_sfc_esc_list)
#print(female_sc_list)
#male_delay_fc, female_delay_fc = categorise_male_female(max_delay_list_fc)
#male_delay_sc, female_delay_sc = categorise_male_female(max_delay_list_sc)
#male_coup_str_fc, female_coup_str_fc = categorise_male_female(max_coup_str_list_fc)
#male_coup_str_sc, female_coup_str_sc = categorise_male_female(max_coup_str_list_sc)
#print(len(male_fc_list))
Example #10
0
    #t_value_fc, p_value_fc = scipy.stats.ranksums(np.arctanh(corr_sfc_efc_male), np.arctanh(corr_sfc_efc_female)) #two tailed t test for corr(sFC, eFC)
    #t_value_sc, p_value_sc = scipy.stats.ranksums(np.arctanh(corr_sfc_esc_male), np.arctanh(corr_sfc_esc_female)) #two tailed t test for corr(sFC, eSC)
    #eff_size_sfc_efc.append(pg.compute_effsize(np.arctanh(corr_sfc_efc_male), np.arctanh(corr_sfc_efc_female), eftype = 'hedges'))

    #eff_size_sfc_esc.append(pg.compute_effsize(np.arctanh(corr_sfc_esc_male), np.arctanh(corr_sfc_esc_female), eftype = 'hedges'))

    #t_value, p_value = scipy.stats.ranksums(np.arctanh(corr_sfc_esc_func_fit_male), np.arctanh(corr_sfc_esc_func_fit_female))
    #eff_size_sfc_esc_func_fit.append(pg.compute_effsize(np.arctanh(corr_sfc_esc_func_fit_male), np.arctanh(corr_sfc_esc_func_fit_female), eftype = 'hedges')) #effect size for coupling strength

    t_value, p_value = scipy.stats.ranksums(
        np.arctanh(corr_sfc_efc_struc_fit_male),
        np.arctanh(corr_sfc_efc_struc_fit_female))
    eff_size_sfc_efc_struc_fit.append(
        pg.compute_effsize(
            np.arctanh(corr_sfc_efc_struc_fit_male),
            np.arctanh(corr_sfc_efc_struc_fit_female),
            eftype='hedges'))  #effect size for coupling strength
    p_val.append(p_value)
r"""
np.savetxt(r"E:\Shraddha\Data\corr_sfc_efc_struc_fit_all_atlas_lc.csv", np.array(corr_sfc_efc_struc_fit_all_atlas).transpose(), delimiter = ',') #saving the corr(sFC, eSC) - functional fit for all atlas where each column represents one atlas in the .csv file


plt.rcParams['font.size'] = '20'
plt.figure(figsize = (16, 8))

male_plots = plt.boxplot(male_data_sfc_efc_struc_fit, positions = np.array(range(l))*2 - 0.3)
female_plots = plt.boxplot(female_data_sfc_efc_struc_fit, positions = np.array(range(l))*2 + 0.3)

set_box_color(male_plots, 'blue') 
set_box_color(female_plots, 'red')