Bootstapping a Data Matrix

조회 수: 5 (최근 30일)
Mike
Mike 2014년 3월 8일
답변: Anshuman 2024년 10월 29일 6:50
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?

답변 (1개)

Anshuman
Anshuman 2024년 10월 29일 6:50
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!

카테고리

Help CenterFile Exchange에서 Resampling Techniques에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by