How do I specify stderr when using bootci to compute bootstrap studentized confidence interval?

I want to compute the studentized bootstrap interval for the mean. The quantity to be computed for each bootstrap sample should be:
(mean(x)-mean(data))./std(x)
where x is a bootstrap sample. I can program this on my own, but I am not sure how to specify the same thing using the function bootci:
ci = bootci(B,{function1,data},'type','stud','stderr',function2);
What should I write for function1 and function2? I have tried several things but the coverages I get from these intervals turn out to be wrong (compared to my own program which I know is correct). I am specifying something incorrectly. Do I specify the divisor std(bootstrapsample) in function1, or in function2 (or in both)? The documentation is sparse.

 Accepted Answer

It is not exactly clear what you are trying to do as you introduce x without explaining what it is. Assuming that you want to bootstrap samples and create a confidence interval round the mean then you do not need to specify function2. function1 would simply be a handle to the mean function as this is what you are looking for the interval on.
ci = bootci(B,{@mean,data},'type','stud')
This will give you a confidence interval around the mean for the variables in each column of data.

5 Comments

x is just resample data. I want the interval around the mean. Writing
ci = bootci(B,{@mean,data},'type','stud')
would use a separate nested bootstrap to estimate the standard error. I want to estimate the standard error directly from the resampled data. This is what the property 'stderr' is supposed to do, by specifiyng an estimator. I just do not know how to specify it in a way that bootci is happy with and I have found no examples using it.
You are correct that this syntax uses your actual bootstrap samples for estimation of the standard error as opposed to the default inner loop bootstrap behavior.
You just need to create a handle for the anonymous function:
data = randn(1000,3);
B = 1000;
function1 = @mean;
function2 = @(x) (mean(x) - mean(data)) ./ std(x);
ci = bootci(B,{function1,data},'type','stud','stderr',function2);
The thing is that those handles get it wrong. What I want is to use bootci to perform the exact equivalent of this:
B = 1e3; %nr resamples
n = 20; % sample size
mu = 3;
d = exprnd(mu,n,1);
meand = mean(d);
x = datasample(d,n*B);
x = vec2mat(x,B);
t = (meand-mean(x))./std(x);
bci_l = meand+std(d)*prctile(t,2.5); % lower bound
bci_u = meand+std(d)*prctile(t,97.5); % upper bound
Although, I noted that this is way faster than bootci so maybe I´ll just use this. Maybe bootci is not vectorized.
I apologize, I made a mistake earlier. The function2 should just be the standard error function to use, and we passed it the function to compute the bootstrap statistic (noting that we should not have a dependence on sample size in this example as MATLAB utilizes the cancellation of this term in the CI calculation (as you did in yours). Therefore what you are looking for is:
B = 1e3; %nr resamples
n = 20; % sample size
mu = 3;
d = exprnd(mu,n,1);
ci = bootci(B,{@mean,data},'type','stud','stderr',@std);
This is the same standard error function MATLAB uses by default, but this will avoid the inner loop you mentioned.
In terms of speed the bootci function can be used on any statistic of your choosing and therefore cannot utilize vectorization as often as your example here.
Sorry for the confusion and I hope this helps.
Thank you very much for the informative and helpful response.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!