played with permutation test
This commit is contained in:
parent
c54da6bf8f
commit
e39f29847f
@ -1,4 +1,5 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
import scipy.stats as st
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
plt.xkcd()
|
plt.xkcd()
|
||||||
@ -10,9 +11,10 @@ n = 200
|
|||||||
a = 0.2
|
a = 0.2
|
||||||
x = rng.randn(n);
|
x = rng.randn(n);
|
||||||
y = rng.randn(n) + a*x;
|
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]
|
rd = np.corrcoef(x, y)[0, 1]
|
||||||
print rd
|
|
||||||
|
|
||||||
# permutation:
|
# permutation:
|
||||||
nperm = 1000
|
nperm = 1000
|
||||||
@ -26,7 +28,13 @@ for i in xrange(nperm) :
|
|||||||
h, b = np.histogram(rs, 20, density=True)
|
h, b = np.histogram(rs, 20, density=True)
|
||||||
|
|
||||||
# significance:
|
# 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 = fig.add_subplot(1, 1, 1)
|
||||||
ax.spines['right'].set_visible(False)
|
ax.spines['right'].set_visible(False)
|
||||||
|
Reference in New Issue
Block a user