diff --git a/inst/boot1way.m b/inst/boot1way.m index 9514f8dd..97501f7a 100755 --- a/inst/boot1way.m +++ b/inst/boot1way.m @@ -175,27 +175,32 @@ argin3 = varargin; narg = numel (argin3); if (narg > 1) - while ischar (argin3{end-1}) - if (strcmpi (argin3{end-1},'bootfun')) - bootfun = argin3{end}; - elseif (strcmpi (argin3{end-1},'nboot')) - nboot = argin3{end}; - elseif (strcmpi (argin3{end-1},'ref')) - ref = argin3{end}; - elseif (any (strcmpi (argin3{end-1},{'Options','Option'}))) - paropt = argin3{end}; - elseif (strcmpi (argin3{end-1},'alpha')) - alpha = argin3{end}; - elseif (any (strcmpi (argin3{end-1},{'DisplayOpt','Display'}))) - DisplayOpt = argin3{end}; - else - error ('boot1way: Unrecognised input argument to boot1way') + name = argin3{end - 1}; + value = argin3{end}; + while (ischar (name)) + switch (lower (name)) + case 'bootfun' + bootfun = value; + case 'nboot' + nboot = value; + case 'ref' + ref = value; + case {'options','option'} + paropt = value; + case 'alpha' + alpha = value; + case {'displayopt','display'} + DisplayOpt = value; + otherwise + error ('boot1way: Unrecognised input argument to boot1way') end - argin3 = {argin3{1:end-2}}; + argin3 = argin3(1:end-2); narg = numel (argin3); if (narg < 1) break end + name = argin3{end - 1}; + value = argin3{end}; end end diff --git a/inst/bootci.m b/inst/bootci.m index 88c2c56c..4f0d2a7f 100755 --- a/inst/bootci.m +++ b/inst/bootci.m @@ -181,33 +181,38 @@ argin3 = varargin; narg = numel (argin3); if (narg > 1) - while (ischar (argin3{end-1})) - if (any (strcmpi ({'Options', 'Option'}, argin3{end-1}))) - paropt = argin3{end}; - elseif (any (strcmpi ('alpha', argin3{end-1}))) - alpha = argin3{end}; - elseif (any (strcmpi ('type', argin3{end-1}))) - type = argin3{end}; - elseif (any (strcmpi ('nbootstd', argin3{end-1}))) - nbootstd = argin3{end}; - elseif (any (strcmpi ('nbootcal', argin3{end-1}))) - nbootcal = argin3{end}; - elseif (any (strcmpi ('strata', argin3{end-1}))) - strata = argin3{end}; - elseif (any (strcmpi ('loo', argin3{end-1}))) - loo = argin3{end}; - elseif (any (strcmpi ('seed', argin3{end-1}))) - seed = argin3{end}; - % Initialise the random number generator with the seed - boot (1, 1, true, seed); - else - error ('bootci: Unrecognised input argument to bootci') + name = argin3{end - 1}; + value = argin3{end}; + while (ischar (name)) + switch (lower (name)) + case {'options', 'option'} + paropt = value; + case 'alpha' + alpha = value; + case 'type' + type = value; + case 'nbootstd' + nbootstd = value; + case 'nbootcal' + nbootcal = value; + case 'strata' + strata = value; + case 'loo' + loo = value; + case'seed' + seed = value; + % Initialise the random number generator with the seed + boot (1, 1, true, seed); + otherwise + error ('bootci: Unrecognised input argument to bootci') end - argin3 = {argin3{1:end-2}}; + argin3 = argin3(1:end-2); narg = numel (argin3); if (narg < 2) break end + name = argin3{end - 1}; + value = argin3{end}; end end if (iscell (argin2)) diff --git a/inst/bootstrp.m b/inst/bootstrp.m index 224a2ee7..1894a0fe 100755 --- a/inst/bootstrp.m +++ b/inst/bootstrp.m @@ -11,15 +11,15 @@ % -- Function File: [BOOTSTAT, BOOTSAM] = bootstrp (...) % % 'BOOTSTAT = bootstrp (NBOOT, BOOTFUN, D)' draws NBOOT bootstrap resamples -% from the data D and returns the statistic computed by BOOTFUN in BOOTSTAT -% [1]. bootstrp resamples from the rows of a data sample D (column vector, -% matrix or cell array). BOOTFUN is a function handle (e.g. specified with -% @), a string indicating the function name, or a cell array where the first -% cell is one of the above function definitions and the remaining cells are -% (additional) input arguments to that function (after the data argument(s)). -% The third input argument is the data (column vector, matrix or cell array), -% which is supplied to BOOTFUN. The resampling method used throughout is -% bootstrap resampling with first order balance [2-3]. +% with replacement from the rows of the data D and returns the statistic +% computed by BOOTFUN in BOOTSTAT [1]. BOOTFUN is a function handle (e.g. +% specified with @) or name, a string indicating the function name, or a +% cell array, where the first cell is one of the above function definitions +% and the remaining cells are (additional) input arguments to that function +% (after the data argument(s)). The third input argument is the data +% (column vector, matrix or cell array), which is supplied to BOOTFUN. The +% simulation method used by default is bootstrap resampling with first order +% balance [2-3]. % % 'BOOTSTAT = bootstrp (NBOOT, BOOTFUN, D1,...,DN)' is as above except that % the third and subsequent input arguments are data are used to create @@ -55,7 +55,7 @@ % MATCH is true. If MATCH is false, a 1-by-N cell array of column vectors % can be provided to specify independent resampling weights for D1 to DN. % -% 'BOOTSTAT = bootstrp (..., 'loo', LOO)' sets the resampling method. If +% 'BOOTSTAT = bootstrp (..., 'loo', LOO)' sets the simulation method. If % LOO is false, the resampling method used is balanced bootstrap resampling. % If LOO is true, the resampling method used is balanced bootknife % resampling [4]. The latter involves creating leave-one-out jackknife @@ -144,19 +144,20 @@ narg = numel (argin3); if (narg > 1) name = argin3{end - 1}; + value = argin3{end}; while (ischar (name)) switch (lower (name)) case {'weights', 'weight'} - w = argin3{end}; + w = value; case {'options', 'option'} - paropt = argin3{end}; + paropt = value; case 'match' - match = argin3{end}; + match = value; case 'seed' - seed = argin3{end}; + seed = value; boot (1, 1, false, seed); % Initialise the RNG with seed case 'loo' - loo = argin3{end}; + loo = value; otherwise error ('bootstrp: Unrecognised input argument to bootstrp') end @@ -166,6 +167,7 @@ break end name = argin3{end - 1}; + value = argin3{end}; end end x = argin3; @@ -373,7 +375,6 @@ w = arrayfun (@(v) round (s{v} * w{v} / mean (w{v}) * nboot), ... 1 : nvar, 'UniformOutput', false); - % Perform balanced bootstrap resampling if (match) bootsam = repmat (mat2cell (boot (n{1}, nboot, loo, seed, w{1}), ... @@ -404,9 +405,11 @@ else % Serial processing if (vectorized) + % Fast: Vectorized evaluation of bootfun on the resampled XR = arrayfun (@(v) x{v}(bootsam{v}), 1 : nvar, 'UniformOutput', false); bootstat = num2cell (bootfun (XR{:}), 2); else + % Slow: Looped evaluation of bootfun on the resampled bootstat = cellfun (@(i) booteval (x, i, bootfun, n, nvar), ... num2cell (cell2mat (bootsam), 1), ... 'UniformOutput', false);