Bootstapping a Data Matrix

5 visualizaciones (últimos 30 días)
Mike
Mike el 8 de Mzo. de 2014
Respondida: Anshuman el 29 de Oct. de 2024 a las 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?

Respuestas (1)

Anshuman
Anshuman el 29 de Oct. de 2024 a las 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!

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by