#!/usr/bin/env python import numpy as np import cPickle import multi_stats import sys if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: show_comp_count.py <comp_count_file> [Nhyp]") sys.exit(1) print("Loading file %s ..." % sys.argv[1]) with open(sys.argv[1], "r") as f: data = cPickle.load(f) Nhyp = int(sys.argv[2]) if len(sys.argv) >= 3 else None # load data and surrogate eigenvalues dlam = data["dlam"] slam = data["slam_ar"] p_vals = multi_stats.compute_eigvals_pvalues(dlam, slam) Nsurr = slam.shape[0] print("Bonferroni (single-level): %d components." % np.sum(multi_stats.bonferroni_test(p_vals, 0.05, Nsurr, Nhyp))) print("Sidak (single-level): %d components." % np.sum(multi_stats.sidak_test(p_vals, 0.05, Nsurr, Nhyp))) print("Bonferroni-Holm (stepdown): %d components." % np.sum(multi_stats.holm_test(p_vals, 0.05, Nsurr, Nhyp))) print("False Discovery Rate: %d components." % np.sum(multi_stats.fdr_test(p_vals, 0.05, Nsurr, Nhyp)))
'orders' : sgf.model_orders()}, f) elif USE_MUVAR: with open('results/hgt500_all_var_muvar_freq_comp_count_cosweights_pilot.bin', 'w') as f: cPickle.dump({ 'dlam' : dlam, 'slam_ar' : slam_ar, 'slam_w1' : slam_w1, 'slam_f' : slam_f, 'orders' : sgf.model_orders()}, f) else: with open('results/hgt500_all_var_data_freq_comp_count_cosweights_pilot.bin', 'w') as f: cPickle.dump({ 'dlam' : dlam, 'slam_ar' : slam_ar, 'slam_w1' : slam_w1, 'slam_f' : slam_f, 'orders' : sgf.model_orders()}, f) # <codecell> figure(figsize = (10,6)) FROM_EIG = 1 TO_EIG = 10 FR = 0 x = np.arange(TO_EIG - FROM_EIG) + FROM_EIG plot(x, dlam[x-1,FR], 'ro-') errorbar(x, np.mean(slam_ar[:, x-1,FR], axis = 0), np.std(slam_ar[:, x-1,FR] * 3, axis = 0), fmt = 'bo-') errorbar(x, np.mean(slam_w1[:, x-1,FR], axis = 0), np.std(slam_w1[:, x-1,FR] * 3, axis = 0), fmt = 'go-') errorbar(x, np.mean(slam_f[:, x-1,FR], axis = 0), np.std(slam_f[:, x-1,FR] * 3, axis = 0), fmt = 'ko-') legend(('Data', 'AR', 'WN', 'F1')) title('Eigenvalues for frequency range %d' % FR) # <codecell> print slam_ar.shape[0] pvals = compute_eigvals_pvalues(dlam, slam_ar) print("Bonferroni correction: %d significant components." % np.sum(bonferroni_test(pvals, 0.05, slam_ar.shape[0]))) print("FDR correction: %d significant components." % np.sum(fdr_test(pvals, 0.05, slam_ar.shape[0])))
figure(figsize=(10, 6)) FROM_EIG = 1 TO_EIG = 10 FR = 0 x = np.arange(TO_EIG - FROM_EIG) + FROM_EIG plot(x, dlam[x - 1, FR], 'ro-') errorbar(x, np.mean(slam_ar[:, x - 1, FR], axis=0), np.std(slam_ar[:, x - 1, FR] * 3, axis=0), fmt='bo-') errorbar(x, np.mean(slam_w1[:, x - 1, FR], axis=0), np.std(slam_w1[:, x - 1, FR] * 3, axis=0), fmt='go-') errorbar(x, np.mean(slam_f[:, x - 1, FR], axis=0), np.std(slam_f[:, x - 1, FR] * 3, axis=0), fmt='ko-') legend(('Data', 'AR', 'WN', 'F1')) title('Eigenvalues for frequency range %d' % FR) # <codecell> print slam_ar.shape[0] pvals = compute_eigvals_pvalues(dlam, slam_ar) print("Bonferroni correction: %d significant components." % np.sum(bonferroni_test(pvals, 0.05, slam_ar.shape[0]))) print("FDR correction: %d significant components." % np.sum(fdr_test(pvals, 0.05, slam_ar.shape[0])))
'dlam': dlam, 'slam_ar': slam_ar, 'slam_w1': slam_w1, 'slam_f': slam_f, 'orders': sgf.model_orders() }, f) log("Saved results to file %s" % fname) # show standard multiple-comparison tests assuming number of hypotheses equal to len(pvals) pvals = compute_eigvals_pvalues(dlam, slam_ar) log("Significance level is %g" % SIG_LEVEL) log("Bonferroni correction: %d significant components." % np.sum(bonferroni_test(pvals, SIG_LEVEL, NUM_SURR))) log("Bonferroni-Holm correction: %d significant components." % np.sum(holm_test(pvals, SIG_LEVEL, NUM_SURR))) fdr_comps = np.sum(fdr_test(pvals, SIG_LEVEL, NUM_SURR)) log("FDR correction: %d significant components." % fdr_comps) log("Rendering eigenvalues from data and from surrogates") f = plt.figure(figsize=(12, 8)) FROM_EIG = 1 TO_EIG = fdr_comps + 5 x = np.arange(TO_EIG - FROM_EIG) + FROM_EIG plt.plot(x, dlam[x - 1], 'ro-') plt.errorbar(x, np.mean(slam_ar[:, x - 1], axis=0), np.std(slam_ar[:, x - 1] * 3, axis=0), fmt='bo-') plt.errorbar(x, np.mean(slam_w1[:, x - 1], axis=0), np.std(slam_w1[:, x - 1] * 3, axis=0),
'slam_f' : slam_f, 'orders' : sgf.model_orders()}, f) log("Saved results to file %s" % fname) else: fname = 'results/%s_var_data_comp_count_cosweights%s.bin' % (DATA_NAME, SUFFIX) with open(fname, 'w') as f: cPickle.dump({ 'dlam' : dlam, 'slam_ar' : slam_ar, 'slam_w1' : slam_w1, 'slam_f' : slam_f, 'orders' : sgf.model_orders()}, f) log("Saved results to file %s" % fname) # show standard multiple-comparison tests assuming number of hypotheses equal to len(pvals) pvals = compute_eigvals_pvalues(dlam, slam_ar) log("Significance level is %g" % SIG_LEVEL) log("Bonferroni correction: %d significant components." % np.sum(bonferroni_test(pvals, SIG_LEVEL, NUM_SURR))) log("Bonferroni-Holm correction: %d significant components." % np.sum(holm_test(pvals, SIG_LEVEL, NUM_SURR))) fdr_comps = np.sum(fdr_test(pvals, SIG_LEVEL, NUM_SURR)) log("FDR correction: %d significant components." % fdr_comps) log("Rendering eigenvalues from data and from surrogates") f = plt.figure(figsize = (12,8)) FROM_EIG = 1 TO_EIG = fdr_comps + 5 x = np.arange(TO_EIG - FROM_EIG) + FROM_EIG plt.plot(x, dlam[x-1], 'ro-') plt.errorbar(x, np.mean(slam_ar[:, x-1], axis = 0), np.std(slam_ar[:, x-1] * 3, axis = 0), fmt = 'bo-') plt.errorbar(x, np.mean(slam_w1[:, x-1], axis = 0), np.std(slam_w1[:, x-1] * 3, axis = 0), fmt = 'go-') plt.errorbar(x, np.mean(slam_f[:, x-1], axis = 0), np.std(slam_f[:, x-1] * 3, axis = 0), fmt = 'ko-') plt.legend(('Data', 'AR', 'WN', 'F1')) plt.title('Eigenvalues for data and surrogates') plt.savefig('%s_eigvals_comparison%s.png' % (DATA_NAME, SUFFIX)) plt.close(f)
import numpy as np import cPickle import multi_stats import sys if __name__ == '__main__': if len(sys.argv) < 2: print("Usage: show_comp_count.py <comp_count_file> [Nhyp]") sys.exit(1) print("Loading file %s ..." % sys.argv[1]) with open(sys.argv[1], 'r') as f: data = cPickle.load(f) Nhyp = int(sys.argv[2]) if len(sys.argv) >= 3 else None # load data and surrogate eigenvalues dlam = data['dlam'] slam = data['slam_ar'] p_vals = multi_stats.compute_eigvals_pvalues(dlam, slam) Nsurr = slam.shape[0] print("Bonferroni (single-level): %d components." % np.sum(multi_stats.bonferroni_test(p_vals, 0.05, Nsurr, Nhyp))) print("Sidak (single-level): %d components." % np.sum(multi_stats.sidak_test(p_vals, 0.05, Nsurr, Nhyp))) print("Bonferroni-Holm (stepdown): %d components." % np.sum(multi_stats.holm_test(p_vals, 0.05, Nsurr, Nhyp))) print("False Discovery Rate: %d components." % np.sum(multi_stats.fdr_test(p_vals, 0.05, Nsurr, Nhyp)))