# generate simulated data d = dict() all_vals = [] siteID = [] for s in range(nSites): # should each site have a different true mean? vals = np.random.normal(trueDiff, sd, nPairs[s]) d[s] = vals siteID.extend(s * np.ones(nPairs[s]).tolist()) all_vals.extend(vals) grouped_vals = [d[s].mean() for s in range(nSites)] # generate bootstrapped samples bs_even = stats.get_bootstrapped_sample(d, even_sample=True, nboot=1000) bs_weighted = stats.get_bootstrapped_sample(d, even_sample=False, nboot=1000) # get pvalue for each method (and for standard Wilcoxon over the population, ignoring sites, one sided) p_even = round( 1 - stats.get_direct_prob(np.zeros(len(bs_even)), bs_even)[0], 5) p_weighted = round( 1 - stats.get_direct_prob(np.zeros(len(bs_even)), bs_weighted)[0], 5) p_wilcox = round( ss.wilcoxon(all_vals, np.zeros(len(all_vals)), alternative='greater').pvalue, 5) p_wilcoxg = round( ss.wilcoxon(grouped_vals, np.zeros(len(grouped_vals)),
print( f"Mean MI: {MI.mean()}, sem: {MI.std() / np.sqrt(MI.shape[0])} \n n total units: {MI.shape[0]}" ) miax.hist(MI, bins=mi_bins, edgecolor='white', color='grey') miax.axvline(0, linestyle='--', color='k') miax.set_xlabel('Modulation Index') miax.set_ylabel(r"$n$ units") # get bootstrapped p-value np.random.normal(123) d = { s: MI[np.argwhere(df['site'].values == s).squeeze()] for s in df['site'].unique() } bootsample = get_bootstrapped_sample(d, even_sample=False, nboot=1000) p = get_direct_prob(bootsample, np.zeros(len(bootsample)))[0] miax.text(mi_bins.min(), miax.get_ylim()[-1] - 2, r"p=%s" % round(p, 4)) # plot noise correlation rsc_path = '/auto/users/hellerc/results/nat_pupil_ms/noise_correlations/' rsc_df = ld.load_noise_correlation('rsc_ev', xforms_model='NULL', path=rsc_path) mask = ~(rsc_df['bp'].isna() | rsc_df['sp'].isna()) rsc_df = rsc_df[mask] d = { s: rsc_df.loc[rsc_df.site == s]['sp'].values - rsc_df.loc[rsc_df.site == s]['bp'].values for s in rsc_df.site.unique() }
lab = r"$\Delta d'^2$" # plot by just collapsing over all sites # generate error bars with hierarchical bootstrap print('generating bootstrap SE, will take a moment') cos_val_delt = ss.binned_statistic(df['cos_dU_evec_test'], df['state_MI'], statistic='mean', bins=cbins).statistic ds = [{ s: df[(df.site == s) & (df['cos_dU_evec_test'] > cbins[i]) & (df['cos_dU_evec_test'] < cbins[i + 1])]['state_MI'].values for s in df.site.unique() } for i in range(len(cbins) - 1)] cos_val_delt_se = np.stack([ np.std(stats.get_bootstrapped_sample(ds[i], nboot=100)) for i in range(len(ds)) ]) du_val_delt = ss.binned_statistic(df['dU_mag_test'], df['state_MI'], statistic='mean', bins=dbins).statistic ds = [{ s: df[(df.site == s) & (df['dU_mag_test'] > dbins[i]) & (df['dU_mag_test'] < dbins[i + 1])]['state_MI'].values for s in df.site.unique() } for i in range(len(cbins) - 1)] du_val_delt_se = np.stack([ np.std(stats.get_bootstrapped_sample(ds[i], nboot=100)) for i in range(len(ds))
gridsize=nbins, cmap=cmap_second, vmin=-1, vmax=1) plt.show() # stats tests # noise variance change np.random.seed(123) nboots = 1000 ds = { s: df_cut[(df_cut.site == s)]['lambda_diff'].values for s in df_cut.site.unique() } ds_boot = stats.get_bootstrapped_sample(ds, nboot=nboots) p = 1 - stats.get_direct_prob(ds_boot, np.zeros(nboots))[0] print("big pupil variance vs. small pupil variance: \n" + \ f"p = {p}\n" + \ f"mean = {np.mean(ds_boot)}\n" + \ f"sem = {np.std(ds_boot)/np.sqrt(nboots)}\n") nboots = 1000 ds = { s: df_cut[(df_cut.site == s)]['mag_diff'].values for s in df_cut.site.unique() } ds_boot = stats.get_bootstrapped_sample(ds, nboot=nboots)
ax[0].set_xlabel('Number of dimensions') ax[1].set_ylabel(r"$\Delta d'^2$") ax[1].set_xticks([0, 1, 2]) ax[1].set_xticklabels(['TDR', 'TDR+1', 'TDR+2']) ax[1].set_xlabel('Number of dimensions') f.tight_layout() f.savefig(fig_fn) # compute stats np.random.seed(123) d = {s: dfn1_dp.loc[dfn1_dp.site==s, 'dp_opt_test'].values - df_dp.loc[df_dp.site==s, 'dp_opt_test'].values for s in df_dp.site.unique()} bootstat = stats.get_bootstrapped_sample(d, nboot=5000) p = 1 - stats.get_direct_prob(np.zeros(len(bootstat)), bootstat)[0] print("========== OVERALL DPRIME ================") print("TDR+1 vs. TDR: pval: {0}".format(p)) print("Mean percent improvement: {0}".format((100 * (dfn1_dp.groupby(by='site').mean()['dp_opt_test'] - \ df_dp.groupby(by='site').mean()['dp_opt_test']) / \ df_dp.groupby(by='site').mean()['dp_opt_test'] ).mean())) d = {s: dfn2_dp.loc[dfn2_dp.site==s, 'dp_opt_test'].values - dfn1_dp.loc[dfn1_dp.site==s, 'dp_opt_test'].values for s in df_dp.site.unique()} bootstat = stats.get_bootstrapped_sample(d, nboot=5000) p = 1 - stats.get_direct_prob(np.zeros(len(bootstat)), bootstat)[0] print("TDR+2 vs. TDR+1: pval: {0}".format(p))