-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.m
More file actions
37 lines (27 loc) · 753 Bytes
/
Copy pathbootstrap.m
File metadata and controls
37 lines (27 loc) · 753 Bytes
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
function sample = bootstrap(data,nTrials,iter,useMedian)
avg = @mean;
if nargin > 3 && useMedian
avg = @median;
end
if nargin < 3
iter = 10000;
end
if nargin < 2
nTrials = 10;
end
if nargin < 1
error('You must provide a sample to bootstrap from');
end
n = numel(data);
data = data(:);
nConditions = n/nTrials;
if mod(nConditions,1) ~= 0
error('Each condition must have the same number of trials');
end
sample = zeros(iter,nConditions);
for qq = 1:iter
sample(qq,:) = avg(reshape(data(randperm(n)),nTrials,nConditions));
end
m = nConditions*iter;
sample = reshape(sample,m,1);
end