Multidimensional bootstrapping

Wrapper for Matlab's bootstrp command, allowing for high dimensional inputs
230 Downloads
Aktualisiert 6. Apr 2015

Lizenz anzeigen

BOOTSTAT = bootstrpXD(dim,NBOOT,BOOTFUN,D1,...)
Does bootstrapping with X dimensional inputs
OVERVIEW
With dim=[], bootstrpXD operates exactly the same the familiar Matlab
bootstrp function, except the matricies D1,... can be greater than
2D.
Assigning a scalar value to dim tells tells bootstrpXD which dimension to
shuffle along ([] for default, dim=1, shuffle rows).

The formats are the same as bootstrp, except for the first argument,
dim. See bootstrp documentation.
BOOTSTAT = bootstrp(dim,NBOOT,BOOTFUN,D1,...)
[BOOTSTAT,BOOTSAM] = bootstrp(dim,...)
BOOTSTAT = bootstrp(dim,...,'Name',Value)
BOOTSTAT = bootstrp(dim,..., 'PARAM1',val1, 'PARAM2',val2, ...) specifies
optional parameter name/value pairs to control how bootstrp performs
computations. Parameter names/values may only appear after the data
arguments used as inputs to BOOTFUN. Parameters are:

'Weights' - Observation weights

'Options' - options including
'UseParallel'
'UseSubstreams'
'Streams'

IMPORTANT NOTE
The return variable of the function handle BOOTFUN must be a scalar
or a vector. Matrix outputs will be reshaped to column vectors.

ALGORITHM
if D1 is ND dimensional, it will first permute D1 to place dim, the
shuffling dimension of interest, first (rows). Then it will pack the
remaining dimensions into the columns, and call Matlab's bootstrp command
using a wrapper function. This wrapper function will undo all of the
aforementioned transformations prior to calling the user's input
function, BOOTFUN. See documentation for bootstrp for more details.

EXAMLES

%% Simpler example
% Generate some data
x = 1:(55*7*2);
x = reshape(x,[55,7,2]);
x = x + 0.1*mean(x(:))*randn([55,7,2]) - mean(x(:));

% Define some function
myfunc = @(x) sum(x,2); % Sum along columns
xout = myfunc(x);

% Plot original data
figure; h1 = plot(squeeze(xout),'k','LineWidth',4);

% Plot bootstrapped data
y = bootstrpXD(2,300,myfunc,x); % Shuffle data along dim 2
y = reshape(y,[300,55,2]); % Unpack bootstrapped data; shuffles along 1st dimension
ybar = mean(y);
ystd = std(y);
hold on; h2 = errorbar(squeeze(ybar),squeeze(ystd),'r.','MarkerSize',20,'LineWidth',1)
legend([h1(1),h2(1)],'Data','Bootstrap Mean & Standard Deviation')


%% Higer dimensional example
% Generate some high dimensional input
x = 1:(6*2*3*4*5);
x = reshape(x,[6,2,3,4,5]);
x = x + 0.1*mean(x(:))*randn([6,2,3,4,5]) - mean(x(:));
sz = size(x);

% Define some function
myfunc = @(x) sum(x);
xout = myfunc(x);

% Plot original data
figure; h1=plot(squeeze(xout(:,2,:,:,5)),'k','LineWidth',4);

% Plot bootstrapped data
y = bootstrpXD([],30,myfunc,x);
y = reshape(y,[30,2,3,4,5]); % Unpack y
ybar = mean(y);
ystd = std(y);
hold on; h2=errorbar(squeeze(ybar(:,2,:,:,5)),squeeze(ystd(:,2,:,:,5)),'r.','MarkerSize',20,'LineWidth',1)
legend([h1(1),h2(1)],'Data','Bootstrap Mean & Standard Deviation')

David Stanley, Boston University

Zitieren als

Dave Stanley (2024). Multidimensional bootstrapping (https://www.mathworks.com/matlabcentral/fileexchange/50416-multidimensional-bootstrapping), MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2007a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Tags Tags hinzufügen

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Veröffentlicht Versionshinweise
1.6.0.0

Updated required products to include statistics toolbox, as this function calls the bootstrp command.

1.5.0.0

Formatted description

1.4.0.0

Provided better examples

1.3.0.0

Updated readme formatting

1.2.0.0

Updated description and in-file documentation

1.1.0.0

Updated description

1.0.0.0