Last active
February 25, 2020 16:19
-
-
Save deep-introspection/b1d979e02975d49502649d6c27b52b84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as st | |
nperm = 100 | |
mix = 0.1 | |
score = np.zeros((5, 17)) | |
nparticipants = [int(i) for i in np.logspace(1, 5, 5)] | |
for ipar, npar in enumerate(nparticipants): | |
for ivar, nvar in enumerate(range(3, 20)): | |
accu = 0 | |
for perm in range(nperm): | |
X1 = np.random.randn(nvar, npar) | |
X2 = np.random.randn(nvar, npar) | |
X1[1, :] = mix * X1[2, :] + (1 - mix) * np.random.randn(1, npar) | |
X2[1, :] = mix * X2[2, :] + (1 - mix) * np.random.randn(1, npar) | |
indexu = np.argwhere(np.triu(np.ones((nvar, nvar)), 1)) | |
C1 = np.triu(np.corrcoef(X1))[indexu[:, 0], indexu[:, 1]] | |
C2 = np.triu(np.corrcoef(X2))[indexu[:, 0], indexu[:, 1]] | |
R, p = st.pearsonr(C1, C2) | |
if p<0.05: | |
accu +=1 | |
score[ipar, ivar] = accu/nperm | |
plt.imshow(score) | |
plt.yticks(range(len(nparticipants)), nparticipants) | |
plt.ylabel("Sample size") | |
plt.xticks(range(17), range(3, 20)) | |
plt.xlabel("Variables number") | |
plt.colorbar() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment