Bootstapping a Data Matrix

3 views (last 30 days)
Mike
Mike on 8 Mar 2014
Answered: Anshuman on 29 Oct 2024
For bootstapping a 3X3 data matrix D = [1 2 3; 4 5 6; 7 8 9] 4 times, is it possible to use the "bootstrp" function to draw with replacement rows from the matrix instead of individual values?

Answers (1)

Anshuman
Anshuman on 29 Oct 2024
Hello,
The "bootstrp" function in MATLAB is primarily designed for resampling data for statistical analysis, and it typically operates on vectors or individual data points.
To achieve row-wise bootstrapping with replacement for a matrix, you can use a custom approach. Here's how you can bootstrap rows from the matrix D four times:
D = [1 2 3; 4 5 6; 7 8 9];
numSamples = 4;
numRows = size(D, 1);
% Preallocate a 3D array to store bootstrap samples
bootstrapSamples = zeros(numRows, size(D, 2), numSamples);
% Bootstrap sampling
for i = 1:numSamples
% Randomly select row indices with replacement
indices = randi(numRows, numRows, 1);
% Create a bootstrap sample by selecting rows
bootstrapSamples(:, :, i) = D(indices, :);
end
for i = 1:numSamples
fprintf('Bootstrap Sample %d:\n', i);
disp(bootstrapSamples(:, :, i));
end
In this code, "randi" is used to randomly select row indices with replacement, and the selected rows are used to create each bootstrap sample. The "bootstrapSamples" array stores each sample as a 2D slice in a 3D array, allowing you to access each sample individually.
Hope it helps!

Tags

Community Treasure Hunt

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

Start Hunting!