LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
mtrace_bootstrap.m
1function ci = mtrace_bootstrap(T,A,resamples)
2
3if nargin == 2
4 resamples = 1000;
5end
6
7% number of samples
8N = length(T);
9% target block length
10BL = 50;
11% number of blocks
12BN = floor(N / BL);
13R = mod(N, BN);
14% actual block lengths
15L = ones(BN,1) * floor(N / BN);
16L(1:R) = L(1:R) + 1;
17% block indices
18I = (1:BN)';
19% compute confidence intervals
20statfunc = @(idx) bf(idx);
21ci = bootci(resamples, statfunc, I);
22
23
24function STATS = bf(idx)
25 [t,a] = blocks(T,A,idx,L);
26 p = mtrace_pc(t,a);
27 B = mtrace_moment(t,a,1,0,1);
28 F = mtrace_moment(t,a,1,1,1);
29 S = mtrace_sigma(t, a);
30 STATS = [p', B', F', S(:)'];
31end
32
33function [t,a] = blocks(T,A,idx,L)
34 n = sum(L(idx));
35 t = zeros(n,1);
36 a = zeros(n,1);
37 last = cumsum(L);
38 first = last - L + 1;
39 next = 1;
40 for i = 1:length(idx)
41 j = idx(i);
42 d1 = next;
43 d2 = next + L(j) - 1;
44 s1 = first(j);
45 s2 = last(j);
46 t(d1:d2) = T(s1:s2);
47 a(d1:d2) = A(s1:s2);
48 next = d2 + 1;
49 end
50end
51
52end