Skip to content

Commit

Permalink
added BOOTDATA as third output argument to bootclust
Browse files Browse the repository at this point in the history
  • Loading branch information
acp29 committed Apr 2, 2024
1 parent 739608e commit e1d17f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
38 changes: 20 additions & 18 deletions inst/bootclust.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,22 @@
% so that bootclust results are reproducible.
%
% 'bootclust (DATA, NBOOT, BOOTFUN, ALPHA, ..., LOO, SEED, NPROC)' also
% sets the number of parallel processes to use for function evaluations
% during bootstrap and jackknife computations on multicore machines. This
% feature requires the Parallel package (in Octave), or the Parallel
% Computing Toolbox (in Matlab).
% sets the number of parallel processes to use for jackknife computations
% and non-vectorized function evaluations during bootstrap and on multicore
% machines. This feature requires the Parallel package (in Octave), or the
% Parallel Computing Toolbox (in Matlab). This option is ignored during
% bootstrap function evaluations when BOOTFUN is vectorized.
%
% 'STATS = bootclust (...)' returns a structure with the following fields
% (defined above): original, bias, std_error, CI_lower, CI_upper.
%
% '[STATS, BOOTSTAT] = bootclust (...)' returns BOOTSTAT, a vector or matrix
% of bootstrap statistics calculated over the bootstrap resamples.
%
% '[STATS, BOOTSTAT, BOOTDATA] = bootclust (...)' returns BOOTDATA, a 1-by-
% NBOOT cell array of datasets generated by cluster or block bootstrap
% resampling.
%
% REQUIREMENTS:
% The function file boot.m (or better boot.mex) and bootcdf, which are
% distributed with the statistics-resampling package.
Expand Down Expand Up @@ -140,8 +145,8 @@
% You should have received a copy of the GNU General Public License
% along with this program. If not, see http://www.gnu.org/licenses/

function [stats, bootstat] = bootclust (x, nboot, bootfun, alpha, clustid, ...
loo, seed, ncpus)
function [stats, bootstat, X] = bootclust (x, nboot, bootfun, alpha, ...
clustid, loo, seed, ncpus)

% Store local functions in a stucture for parallel processes
localfunc = struct ('col2args', @col2args, ...
Expand All @@ -159,7 +164,7 @@
if (nargin > 8)
error ('bootclust: Too many input arguments')
end
if (nargout > 2)
if (nargout > 3)
error ('bootclust: Too many output arguments')
end

Expand Down Expand Up @@ -407,7 +412,7 @@
M = cell2mat (cellfun (@(i) repmat (x(:, i), 1, 2), ...
num2cell (1 : nvar), 'UniformOutput', false));
else
M = repmat (x, 1, 2);
M = repmat (x, 1, 2);
end
if (any (szx > 1))
VECTORIZED = false;
Expand Down Expand Up @@ -442,30 +447,27 @@

% Perform resampling of clusters
bootsam = boot (nx, nboot, loo);
X = arrayfun (@(i) x(bootsam(i, :)), 1 : nx, 'UniformOutput', false);
X = [X{:}]';
X = arrayfun (@(b) cell2mat (x(bootsam(:, b))), 1 : nboot, ...
'UniformOutput', false);

% Perform the function evaluations
if VECTORIZED
X = reshape (vertcat (X{:}), n, nboot * nvar);
bootstat = bootfun (X);
if ( (VECTORIZED) && (nvar == 1) )
bootstat = bootfun (cell2mat (X));
else
if (ncpus > 1)
% Evaluate bootfun on each bootstrap resample in PARALLEL
X = arrayfun (@(i) vertcat (X(:,i)), 1 : nboot, 'UniformOutput', false);
if (ISOCTAVE)
% OCTAVE
bootstat = parcellfun (ncpus, @(X) bootfun (cell2mat (X)), X, ...
bootstat = parcellfun (ncpus, @(x) bootfun (x), X, ...
'UniformOutput', false);

else
% MATLAB
bootstat = cell (1, nboot);
parfor b = 1 : nboot; bootstat{b} = bootfun (cell2mat (X{:, b})); end
parfor b = 1 : nboot; bootstat{b} = bootfun (X{:, b}); end
end
else
% Evaluate bootfun on each bootstrap resample in SERIAL
bootstat = cell2mat (arrayfun (@(b) bootfun (vertcat (X{:,b})), ...
bootstat = cell2mat (arrayfun (@(b) bootfun (X{:, b}), ...
1 : nboot, 'UniformOutput', false));
end
end
Expand Down
4 changes: 2 additions & 2 deletions inst/bootknife.m
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,8 @@ function print_output (stats, nboot, alpha, l, m, bootfun_str, strata)

function retval = col2args (func, x, szx)

% Usage: retval = col2args (func, x, nvar)
% col2args evaluates func on the columns of x. When nvar > 1, each of the
% Usage: retval = col2args (func, x, szx)
% col2args evaluates func on the columns of x. When sum(szx) > 1, each of the
% blocks of x are passed to func as a separate arguments.

% Extract columns of the matrix into a cell array
Expand Down

0 comments on commit e1d17f5

Please sign in to comment.