-
Notifications
You must be signed in to change notification settings - Fork 2
/
ComputePValueBehaviorAnatomySupervoxel_asymm.m
96 lines (73 loc) · 2.36 KB
/
ComputePValueBehaviorAnatomySupervoxel_asymm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function [pvalue,nsmaller,sample_baindex] = ...
ComputePValueBehaviorAnatomySupervoxel_asymm(normbehaviordata,supervoxeldata_t,baindex,nsamples,dosavesamples,nsmaller,nsamples0)
if ischar(normbehaviordata),
matfilename = normbehaviordata;
savename_iter = supervoxeldata_t;
load(matfilename);
end
if ~exist('dosavesamples','var'),
dosavesamples = false;
end
if isdeployed,
rnginfo = rng('shuffle');
else
rnginfo = [];
end
% normbehaviordata_reshape is nlines x 1 x nstats
% supervoxeldata is nlines x nsupervoxels
nsupervoxels = size(supervoxeldata_t,1);
nstatscurr = size(normbehaviordata,2);
nlinescurr = size(supervoxeldata_t,2);
if ~exist('nsamples','var'),
nsamples = 1000;
end
if exist('nsmaller','var') && exist('nsamples0','var') && ...
~isempty(nsmaller) && nsamples0 > 0,
else
nsmaller = zeros([nsupervoxels,nstatscurr],'single');
nsamples0 = 0;
end
if dosavesamples,
sample_baindex = zeros([nsupervoxels,nstatscurr,nsamples],'single');
else
sample_baindex = [];
end
supervoxeldata_sum = sum(supervoxeldata_t,2);
for samplei = 1:nsamples,
if mod(samplei,100) == 0,
fprintf('Sample %d/%d\n',samplei,nsamples);
drawnow;
end
% sample with replacement from all lines
r = randsample(nlinescurr,nlinescurr,true)';
% % sample with replacement from all lines except this one
% r = randsample(nlinescurr-1,nlinescurr,true)';
% idx = r >= 1:nlinescurr;
% r(idx) = r(idx)+1;
normbehaviordata_curr = normbehaviordata(r,:);
normbehaviordata_sum = sum(normbehaviordata_curr,1);
baintersection0 = supervoxeldata_t*normbehaviordata_curr;
baunion = bsxfun(@plus,normbehaviordata_sum,supervoxeldata_sum);
baindex0 = baintersection0./baunion*2;
idx = bsxfun(@lt,baindex0,baindex);
nsmaller(idx) = nsmaller(idx) + 1;
if dosavesamples,
sample_baindex(:,:,samplei) = baindex0;
end
end
pvalue = 1 - nsmaller/(nsamples+nsamples0);
if exist('matfilename','var'),
nsamples0 = nsamples + nsamples0; %#ok<NASGU>
[p,n,~] = fileparts(matfilename);
if exist('savename_iter','var'),
nt = savename_iter;
else
[~,nt] = fileparts(tempname);
end
savefile = fullfile(p,sprintf('%s_samples%s_%s.mat',n,datestr(now,'yyyymmddTHHMMSSFFF'),nt));
if dosavesamples,
save(savefile,'pvalue','nsmaller','nsamples0','rnginfo','sample_baindex');
else
save(savefile,'pvalue','nsmaller','nsamples0','rnginfo');
end
end