From e39f29847fa9ceec99d4ed27471cf847f95ceb0e Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 4 Dec 2017 19:15:09 +0100 Subject: [PATCH] played with permutation test --- bootstrap/lecture/permutecorrelation.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bootstrap/lecture/permutecorrelation.py b/bootstrap/lecture/permutecorrelation.py index 0f2ac14..ab1a583 100644 --- a/bootstrap/lecture/permutecorrelation.py +++ b/bootstrap/lecture/permutecorrelation.py @@ -1,4 +1,5 @@ import numpy as np +import scipy.stats as st import matplotlib.pyplot as plt plt.xkcd() @@ -10,9 +11,10 @@ n = 200 a = 0.2 x = rng.randn(n); y = rng.randn(n) + a*x; +#x = rng.exponential(1.0, n); +#y = rng.exponential(2.0, n) + a*x; rd = np.corrcoef(x, y)[0, 1] -print rd # permutation: nperm = 1000 @@ -26,7 +28,13 @@ for i in xrange(nperm) : h, b = np.histogram(rs, 20, density=True) # significance: -rq = np.percentile(rs, 95.0); +rq = np.percentile(rs, 95.0) +print('Measured correlation coefficient = %.2f, correlation coefficient at 95%% percentile of bootstrap = %.2f' % (rd, rq)) +ra = 1.0-0.01*st.percentileofscore(rs, rd) +print('Measured correlation coefficient %.2f is at %.4f percentile of bootstrap' % (rd, ra)) + +rp, ra = st.pearsonr(x, y) +print('Measured correlation coefficient %.2f is at %.4f percentile of test' % (rp, ra)) ax = fig.add_subplot(1, 1, 1) ax.spines['right'].set_visible(False)