Confidence interval for slope and intersect using bootstrapping
4 次查看(过去 30 天)
显示 更早的评论
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
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
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!