bootstrap regression giving 2 different answers, not sure why

4 views (last 30 days)
Hi,
I am trying to generate confidence intervals for coefficients of a linear regression using the bootstrp() function in matlab. I am confused because when I call the function using two different methods that I believe should result in equivalent answers (code attached), I am getting different results from the bootstrp() function. I'm sure the issue is in my understanding of how the second method of calling bootstrp() is working, but I would appreciate insight into why this is and how to make the two calls have equivalent answers.
Thank you
%use sample data for this
load hald
x=[ones(size(heat)),ingredients]; %Vandermonde matrix
y=heat;
[bootstats_one]=bootstrp(10,'regress',y,x); %this method gives the correct results
[bootstats_two]=bootstrp(10,@(bootr)regress(bootr,x),y) %this gives different results

Accepted Answer

Adam Danz
Adam Danz on 1 Oct 2021
According to the bootstrp documentation, bootfun should be a function handle but bootstrp merely calls feval which accepts character vectors of function names which is why there isn't an error.
In the syntax bootstat = bootstrp(nboot,bootfun,d1,...,dN), d1,...dN are the variables to be sampled where rows are observations. That's correctly set up in your first call to bootstrp. However, in your second call to bootstrp you are only sampling the rows of y while referencing the same set of x values for each bootstrap repetition.
The line below shows the correct way to set it up.
[bootstats_two]=bootstrp(10,@(ybs,xbs)regress(ybs,xbs),y,x)
Now the rows and y and x will be correctly paired.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!