Skip to content

Commit 98031cb

Browse files
committed
verified matlabMaxR_test
1 parent f17accb commit 98031cb

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

testCode/matlabMaxR_Test.m

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
% Taku Ito
2+
% 6/16/2017
3+
4+
% Test script to test code for permutation testing in matlab
5+
clear all
6+
clc
7+
8+
addpath('../matlabCode/')
9+
10+
%% Create data set
11+
numVoxels = 100;
12+
numSubjs = 100;
13+
sigEffects = 20;
14+
behavArr = randn(numSubjs,1);
15+
16+
disp('Running simulation - upper-tailed test...')
17+
disp(['Running correlations on ' num2str(numVoxels) ' voxels (' num2str(numVoxels) ' independent tests) with ' num2str(numSubjs) ' subjects'])
18+
disp([num2str(sigEffects) ' significant real effects'])
19+
20+
tic
21+
% Construct data set
22+
dataSet = zeros(numVoxels,numSubjs);
23+
for vox=1:numVoxels
24+
if vox <= sigEffects
25+
dataSet(vox,:) = randn(1,numSubjs) + behavArr';
26+
else
27+
dataSet(vox,:) = randn(1,numSubjs);
28+
end
29+
end
30+
31+
32+
%% Run permutation test
33+
alpha = .05;
34+
[r, maxR_thresh] = maxR(dataSet,behavArr,...
35+
'alpha', alpha, ...
36+
'tail', 1, ...
37+
'permutations',10000, ...
38+
'nproc', 10);
39+
toc
40+
41+
disp(['Number of true effects: ' num2str(sigEffects)])
42+
disp(['Number of statistically significant effects (p < .05): ' num2str(sum(r>maxR_thresh))])
43+
44+
%%%%%%%%%%%%%%%%%
45+
disp('########################################')
46+
disp('Running simulation - lower-tailed test...')
47+
disp(['Running correlations on ' num2str(numVoxels) ' voxels (' num2str(numVoxels) ' independent tests) with ' num2str(numSubjs) ' subjects'])
48+
disp([num2str(sigEffects) ' significant real effects'])
49+
50+
tic
51+
% Construct data set (already contrasted)
52+
dataSet = zeros(numVoxels,numSubjs);
53+
for vox=1:numVoxels
54+
if vox <= sigEffects
55+
dataSet(vox,:) = randn(1,numSubjs) - behavArr';
56+
else
57+
dataSet(vox,:) = randn(1,numSubjs);
58+
end
59+
end
60+
61+
62+
%% Run permutation test
63+
alpha = .05;
64+
[r, maxR_thresh] = maxR(dataSet, behavArr, ...
65+
'alpha', alpha, ...
66+
'tail', -1, ...
67+
'permutations',10000, ...
68+
'nproc', 10);
69+
toc
70+
71+
disp(['Number of true effects: ' num2str(sigEffects)])
72+
disp(['Number of statistically significant effects (p < .05): ' num2str(sum(r<maxR_thresh))])
73+
74+
%%%%%%%%%%%%%%%%%
75+
disp('########################################')
76+
disp('Running simulation - two-tailed test...')
77+
disp(['Running correlations on ' num2str(numVoxels) ' voxels (' num2str(numVoxels) ' independent tests) with ' num2str(numSubjs) ' subjects'])
78+
disp([num2str(sigEffects) ' significant real effects'])
79+
80+
tic
81+
% Construct data set (already contrasted)
82+
dataSet = zeros(numVoxels,numSubjs);
83+
for vox=1:numVoxels
84+
if vox <= sigEffects
85+
% if voxel is odd, mave it be a negative contrast effect
86+
if mod(vox,2) == 1
87+
dataSet(vox,:) = randn(1,numSubjs) - behavArr';
88+
% if voxel is even, mave it be a positive contrast effect
89+
elseif mod(vox,2)==0
90+
dataSet(vox,:) = randn(1,numSubjs) + behavArr';
91+
end
92+
else
93+
dataSet(vox,:) = randn(1,numSubjs);
94+
end
95+
end
96+
97+
%% Run permutation test
98+
alpha = .05;
99+
[r, maxR_thresh] = maxR(dataSet, behavArr, ...
100+
'alpha', alpha, ...
101+
'tail', 0, ...
102+
'permutations',10000, ...
103+
'nproc', 10);
104+
toc
105+
106+
disp(['Number of true effects: ' num2str(sigEffects)])
107+
disp(['Number of statistically significant effects (p < .05): ' num2str(sum(abs(r)>maxR_thresh))])

0 commit comments

Comments
 (0)