-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap_lme.m
52 lines (42 loc) · 1.5 KB
/
bootstrap_lme.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
function npeaks = bootstrap_lme(Atb,timevar,timevarname,N,lmefunc,fixeff,varargin)
if nargin == 6
H =2; E =0.5; dh =0.1; C = 4;
else
H = varargin{1};
E = varargin{2};
dh = varargin{3};
C = varargin{4};
end
npeaks = cell(N,1);
nvars = size(Atb,1);
Atb.(timevarname) = zeros(nvars,1);
if strcmp(timevarname,fixeff) % time varying fix effect
parfor n = 1:N
Atb_shuff = Atb;
indshuff = randi(nvars,nvars,1);
timeshuff = timevar(indshuff,:);
teig_shuff = zeros(1,size(timevar,2));
for t = 1:size(timevar,2)
Atb_shuff.(fixeff) = timeshuff(:,t);
lme_shuff = fitlme(Atb_shuff, lmefunc );
teig_shuff(t) = lme_shuff.Coefficients.tStat(strcmp(lme_shuff.CoefficientNames,fixeff));
end
[tfce_shuff] = matlab_tfce_transform(teig_shuff,H,E,C,dh);
npeaks{n}= [min(tfce_shuff), max(tfce_shuff)];
end
else
parfor n = 1:N
Atb_shuff = Atb;
Atb_shuff.(fixeff) = Atb.(fixeff)(randi(nvars,nvars,1));
teig_shuff = zeros(1,size(timevar,2));
for t = 1:size(timevar,2)
Atb_shuff.(timevarname) = timevar(:,t);
lme_shuff = fitlme(Atb_shuff, lmefunc );
teig_shuff(t) = lme_shuff.Coefficients.tStat(strcmp(lme_shuff.CoefficientNames,fixeff));
end
[tfce_shuff] = matlab_tfce_transform(teig_shuff,H,E,C,dh);
npeaks{n} = [min(tfce_shuff), max(tfce_shuff)];
end
end
npeaks = cell2mat(npeaks);
end