MATLAB Answers

Confidence interval for slope and intersect using bootstrapping

3 views (last 30 days)
Emma
Emma on 12 Apr 2017
Answered: OCDER on 28 Sep 2018
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 Comment
Aidan Starr
Aidan Starr on 28 Sep 2018
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

Sign in to comment.

Answers (1)

OCDER
OCDER on 28 Sep 2018
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