Hi Ricardo,
It seems like you want to adapt the sample size for the inner bootstrap to "NB2_size". To adapt the "bootci" function, you can create a custom sampling function that generates bootstrap samples of the desired size and then pass the function to "bootci".
You can do it by first defining a custom sampling function that takes the data and the desired sample size as inputs and outputs the mean of the bootstrap sample and then using this custom function with the "bootci" function to compute the confidence intervals.
Here is a sample MATLAB code for the above approach
data = rand(1,3000);
% Define the number of bootstrap samples for the outer and inner bootstraps
nBoot1 = 5000; % Number of bootstrap samples in the first step
nBoot2 = 2000; % Number of bootstrap samples in the second step (inner bootstrap)
% Define the sample size for the inner bootstrap
NB2_size = 500;
% Compute the 90% confidence interval using the custom bootstrap function
% Pass a function handle to the custom sampling function along with the extra parameter NB2_size
[bci, bmeans] = bootci(nBoot2, {@customBootstrapSample, data, NB2_size}, 'alpha', 0.1, 'type', 'per');
% Compute the bootstrap sample mean
bmu = mean(bmeans);
% Display the results
disp('Bootstrap Confidence Interval:');
disp(bci);
disp('Bootstrap Sample Mean:');
disp(bmu);
% Custom sampling function for the inner bootstrap
function bootSampleMean = customBootstrapSample(data, sampleSize)
% Generate a bootstrap sample of the specified size
bootSample = data(randi(numel(data), sampleSize, 1));
% Calculate the mean of the bootstrap sample
bootSampleMean = mean(bootSample);
end
You can replace the data with your original data and adjust the code accordingly. The "customBootstrapSample" function takes "data" and "sampleSize" and returns the mean of a bootstrap sample with "sampleSize" elements. The "bootci" function is then called with a function handle to "customBootstrapSample", and "NB2_size" is passed as an additional argument.
You can refer to the following documentation for more information about "bootci": https://www.mathworks.com/help/stats/bootci.html.
I hope it helps!