Confidence interval for slope and intersect using bootstrapping

조회 수: 8 (최근 30일)
Emma
Emma 2017년 4월 12일
답변: OCDER 2018년 9월 28일
Hi!
I have 2 variables with some NaNs. I use bootstrapping to get the slope and intersect from a linear regression:
good = isnan(var1) + isnan(var2);
p_bootstrp = bootstrp(1000, 'polyfit',var1(good == 0),var2(good == 0),1);
med_slope = median(p_bootstrp(:,1)); % The slope
med_intersect = median(p_bootstrp(:,2)); % The intersect
But, I cannot figure out how to get the confidence intervals for this using bootci. I thought that I could use bootci the same way as when getting a confidence interval for the corelation coefficient but that doesn't work.
ci_slope = bootci(5000, @polyfit, var1(good == 0), var2(good == 0));
How do I calculate the confindence interval for linear regression using bootstrapping? Is there a Matlab function to do it?
Thanks,
Emma
  댓글 수: 1
Aidan Starr
Aidan Starr 2018년 9월 28일
Hi Emma,
Not sure if I'm missing something, but looks like you just need to include the order for polyfit to work.
ie:
ci_slope = bootci(5000, @polyfit, var1(good == 0), var2(good == 0),1);
Hope this helps, Aidan

댓글을 달려면 로그인하십시오.

답변 (1개)

OCDER
OCDER 2018년 9월 28일
I believe it's just the percentile itself for bootstraps. If you get 1000 bootstrapped sample and results, then take the top 2.5% for the upper bound, bottom 2.5% for the lower bound, and you get your 95% CI.
% 95% CI means 2.5% bottom and top
LowerCI = prctile(p_bootstrp, 2.5, 1); Lower Slope, Lower Intersect
UpperCI = prctile(p_bootstrp, 97.5, 1); Upper Slope, Lower Intersect
To get an exact CI, you need to find the actual values and recompute the CI (just more details)
See Page 5

Community Treasure Hunt

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

Start Hunting!

Translated by