How to change bootci sample size (bootstrap confidence interval)?
5 views (last 30 days)
Show older comments
I'd like to adapt MATLAB's bootci function to perform resampling with a specified size.
Currently, I've implemented a basic resampling method with a fixed sample size (sizeBoot).
Here's the (slow) code snippet:
% Create random data from a normal distribution
% with mean 28.25 and sd 8.5.
data = (randn(1,100000)*8.5 + 28.25)';
nBoot = 2000; % Number of bootstraps
sizeBoot = 500; % Resampling size (bootci default is size(data))
bootMeans = nan(1, nBoot);
for i = 1:Boot_number
bootMeans(i) = mean(data(randi(numel(data), sizeBoot)));
end
% Bootci (fast)
[bci,bmeans] = bootci(nBoot,{@mean,data},'alpha',.1,'type','per'); %90 confidence interval
I believe the solution involves modifying MATLAB's bootci and bootstrp functions.
However, this task exceeds my current capabilities. Could you provide any guidance or ideas on how to achieve this modification effectively (while keeping the confidence interval types and parallel options)?
3 Comments
Adam Danz
on 19 Feb 2024
The percentile CIs can be computed from the bootMeans created in your for-loop.
data = (randn(100000,1)*8.5 + 28.25);
nBoot = 2000; % Number of bootstraps
sizeBoot = 500; % Resampling size (bootci default is size(data))
alpha = 0.1;
n = numel(data);
bootMeans = nan(nBoot,1);
for i = 1:nBoot
bootMeans(i) = mean(data(randi(n, sizeBoot, 1)));
end
interval = [alpha/2, 1 - alpha/2] * 100;
CI = prctile(bootMeans,interval)
A comparsion of this method vs bootci is explained here and shows that these methods are equivalent.
Here's the vectorized version.
data = (randn(100000,1)*8.5 + 28.25);
nBoot = 2000; % Number of bootstraps
sizeBoot = 500; % Resampling size (bootci default is size(data))
alpha = 0.1;
n = numel(data);
bootMeans = mean(data(randi(n, sizeBoot, nBoot)));
interval = [alpha/2, 1 - alpha/2] * 100;
CI = prctile(bootMeans,interval)
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!