def _nbs_helper(x, y, expected_pval, atol=.05, thresh=.1, ntrials=25, paired=False): # comment pval, _, _ = bct.nbs_bct(x, y, thresh, k=ntrials, paired=paired) print(pval, expected_pval) assert np.allclose(pval, expected_pval, atol=atol)
def _nbs_helper(x, y, expected_pval, atol=.05, thresh=.1, ntrials=25, paired=False): # comment pval, _, _ = bct.nbs_bct(x, y, thresh, k=ntrials, paired=paired) print pval, expected_pval assert np.allclose(pval, expected_pval, atol=atol)
def nbs_and_graphs(corr1, corr2, p_thresh, k, atlas, verbose): coordinates = plotting.find_parcellation_cut_coords(labels_img=atlas) corr1 = np.asarray(corr1, dtype="float") corr2 = np.asarray(corr2, dtype="float") if corr1.shape[0] != corr1.shape[1]: corr1 = np.moveaxis(corr1, 0, -1) corr2 = np.moveaxis(corr2, 0, -1) thresh = stats.t.isf(p_thresh, corr1.shape[2]) pval, adj, _ = bct.nbs_bct( corr1, corr2, thresh, k=k, tail="both", paired=True, verbose=verbose ) print(pval) gridkw = dict(width_ratios=[1, 2]) fig, (ax1, ax2) = plt.subplots(1, 2, gridspec_kw=gridkw, figsize=(15, 4)) g = sns.heatmap(adj, square=True, ax=ax1, cmap="Greys") h = plotting.plot_connectome_strength( adj, node_coords=coordinates, cmap="YlGnBu", axes=ax2 ) return pval, adj, fig
) f_phys_corrmats.append(corrmat.values) f_phy = np.dstack((f_phys_corrmats)) # run nbs for female > male in physics d_freedom = len(f_df.index) - 2 d_freedom t_crit_sex = t.ppf(0.95, d_freedom) m_phy.shape phy_pval, phy_adj, phy_null = bct.nbs_bct(f_phy, m_phy, thresh=t_crit_sex, k=1000, tail="left", paired=False, verbose=False) pd.DataFrame(phy_adj, index=labels, columns=labels).to_csv( join(data_dir, "m-gt-f_phy-regionwise_comp_adj_{0}.csv".format(phy_pval))) phy_pval, phy_adj, phy_null = bct.nbs_bct(f_phy, m_phy, thresh=t_crit_sex, k=1000, tail="right", paired=False, verbose=False) pd.DataFrame(phy_adj, index=labels, columns=labels).to_csv( join(data_dir, "f-gt-m_phy-regionwise_comp_adj_{0}.csv".format(phy_pval)))