-
Notifications
You must be signed in to change notification settings - Fork 6
/
bootstrap_tol.m
76 lines (65 loc) · 2.35 KB
/
bootstrap_tol.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
function bounds = bootstrap_tol(out_warp, quants, nboot, alpha)
% BOOTSTRAP_TOL Boostrapped tolerance bounds
% -------------------------------------------------------------------------
%
% This function models the functional data using a Gaussian model extracted
% from the principal components of the srvfs
%
% Usage: bounds = bootstrap_tol(out_warp, quants, nboot, alpha)
%
% Inputs:
% out_warp: fdawarp object of aligned data
% quant: array of quantiles of normal - example [.0275, 0.975]
% nboot: number of bootstraps
% alpha: significance level - example .05
%
% Output:
% Structure containing
% lwrtol: lower tolerance fs
% uprtol: upper tolerance fs
% mnCI: tolerance of mean fs
% lwrtol_gam: lower tolerance gams
% uprtol_gam: upper tolerance gams
% mnCI_gam: tolerance of mean gams
if (~isa(out_warp,'fdawarp'))
error('Require input of class fdawarp');
end
if (isempty(out_warp.fn))
error('Please align using method time_warping');
end
fn = out_warp.fn;
time = out_warp.time;
% bootstrap CI's
bootlwr = zeros(length(time),nboot);
bootupr = zeros(length(time),nboot);
bootmean = zeros(length(time),nboot);
bootlwr_gam = zeros(length(time),nboot);
bootupr_gam = zeros(length(time),nboot);
bootmean_gam = zeros(length(time),nboot);
parpool();
fprintf('Bootstrap Sampling. \n');
obj = ProgressBar(nboot, ...
'IsParallel', true, ...
'WorkerDirectory', pwd, ...
'Title', 'Progress' ...
);
obj.setup([], [], []);
parfor ii = 1:nboot
samples = gauss_model(out_warp, size(fn,2), false);
bootlwr(:,ii) = mean(samples.fs,2)+norminv(quants(1),0,1)*sqrt(var(samples.fs,0,2));
bootupr(:,ii) = mean(samples.fs,2)+norminv(quants(2),0,1)*sqrt(var(samples.fs,0,2));
bootmean(:,ii) = mean(samples.fs,2);
bootlwr_gam(:,ii) = mean(samples.gams)+norminv(quants(1),0,1)*sqrt(var(samples.gams));
bootupr_gam(:,ii) = mean(samples.gams)+norminv(quants(2),0,1)*sqrt(var(samples.gams));
bootmean_gam(:,ii) = mean(samples.gams);
updateParallel([], pwd);
end
obj.release();
delete(gcp('nocreate'))
% get CI's from bootstraps
bounds.lwrtol = quantile(bootlwr,alpha/2,2);
bounds.uprtol = quantile(bootupr,1-alpha/2,2);
bounds.mnCI = quantile(bootmean,[alpha/2, 1-alpha/2],2);
bounds.lwrtol_gam = quantile(bootlwr_gam,alpha/2,2);
bounds.uprtol_gam = quantile(bootupr_gam,1-alpha/2,2);
bounds.mnCI_gam = quantile(bootmean_gam,[alpha/2, 1-alpha/2],2);