forked from LIMO-EEG-Toolbox/limo_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimo_bootse.m
67 lines (56 loc) · 1.7 KB
/
limo_bootse.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
function bse = limo_bootse(varargin)
% Compute a bootstrapped standard error
% We estimate the standard error of the est statistic by the standard
% deviation of the bootstrap replications Efron & Tibshinari 1993, chapter 6
%
% INPUT
% limo_bse = bootse(x,nboot,est,q)
% x is a vector
% nboot the number of bootstrap to perform
% est is the estimator to use, either Harrell-Davis (='limo_hd')
% or median (='median')
% q is the decile if est = limo_hd
%
% Wilcox 2005, p.44-45 - See Wilcox p.44-46
% GA Rousselet, University of Glasgow, Dec 2007
% C Pernet make it work with LIMO_EEG
% Version 1 June 2010
% -----------------------------
% Copyright (C) LIMO Team 2010
x = varargin{1};
nboot = varargin{2};
est = varargin{3};
if length(varargin) == 4
q = varargin{4};
end
rand('state',sum(100*clock));
n=length(x); % number of subjects/tirals
boot = zeros(1,nboot);
switch lower(est)
case {'hd'} % Harrell-Davis estimator
for kk=1:nboot % do bootstrap
eval(['boot(kk)=',est,'(randsample(x,n,true),q);'])
end
otherwise
for kk=1:nboot % do bootstrap
eval(['boot(kk)=',est,'(randsample(x,n,true));'])
end
end
bse = std(boot,0); % normalize by (n-1)
end
%% Harell-Davis subfunction
function thetaq = hd(x,q)
% Compute the Harrell-Davis estimate of the qth quantile
% The vector x contains the data, and the desired quantile is q
% The default value for q is .5.
% % Original R code by Rand Wilcox
% See Wilcox p.71, 139
% GAR, University of Glasgow, Dec 2007
n=length(x);
m1=(n+1).*q;
m2=(n+1).*(1-q);
vec=1:length(x);
w=betacdf(vec./n,m1,m2)-betacdf((vec-1)./n,m1,m2);
y=sort(x);
thetaq=sum(w(:).*y(:));
end