Hi, help with bootsrap

4 ビュー (過去 30 日間)
Ceci Pascucci
Ceci Pascucci 2016 年 12 月 6 日
回答済み: Ayush Aniket 2025 年 1 月 27 日 5:09
I need to use the bootstrap method to resample a column vector of size k, for n times, but with sample size that is not the same of the distribution (vector). In other words, out of a 532x1 vector I need to take out 10.000 samples of size 120 with replacement. I'm not very familiar with MatLab and not even with statistics, but I'm trying. Here's what I tried so far: - bootstrp function, where I specified (among the other things) the number of repetitions, but I don't how to select a sample size smaller than the size of the distribution. - randsample function, where I specified sample size but don't know how to repeat for 10.000 times with replacement - h = distribution(ceil(n*rand(1,n)) was suggested on a manual, but I'm not sure how it is used or fits in. Thanks for the help. Ceci

回答 (1 件)

Ayush Aniket
Ayush Aniket 2025 年 1 月 27 日 5:09
You want to draw 10,000 samples of size 120 from a vector of size 532 with replacement following bootstrap resampling. Using the randsample function in a loop will help you achieve this requirement. Refer the code snippet below:
% Assume 'data' is your 532x1 column vector
data = rand(532, 1); % Example data, replace with your actual data
% Define parameters
num_samples = 10000; % Number of bootstrap samples
sample_size = 120; % Size of each sample
% Preallocate a matrix to store the bootstrap samples
bootstrap_samples = zeros(sample_size, num_samples);
% Perform bootstrap resampling
for i = 1:num_samples
bootstrap_samples(:, i) = randsample(data, sample_size, true);
end
Why is this the correct approach?
  • randsample allows you to specify a sample size that is different from the original dataset size.
  • Bootstrap resampling requires sampling with replacement to mimic the process of drawing from the same population multiple times. randsample provides a straightforward way to specify this with its true parameter.
  • The loop structure allows you to repeat the sampling process a specified number of times (e.g., 10,000). Each iteration of the loop produces one bootstrap sample, effectively simulating the variability you would expect from repeated sampling.
  • Each sample drawn in the loop is independent of the others, which is a fundamental property of bootstrap resampling.

カテゴリ

Help Center および File ExchangeResampling Techniques についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by