bootstrap regression giving 2 different answers, not sure why

조회 수: 6 (최근 30일)
Margaret Scott
Margaret Scott 2021년 10월 1일
댓글: Margaret Scott 2021년 10월 1일
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

채택된 답변

Adam Danz
Adam Danz 2021년 10월 1일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resampling Techniques에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by