Why is bootci giving different interval than prctile?

1 回表示 (過去 30 日間)
Jakub
Jakub 2024 年 12 月 16 日
コメント済み: Jakub 2024 年 12 月 16 日
I was trying to show confidence interval on a histogram with the following code.
n = 10e3;
data = randn(n,1);
alpha = 0.05;
nboot = 10e3;
mu = mean(data);
[ci,bootstat] = bootci(nboot,{@mean,data},"Alpha",alpha,"Type","percentile");
bootstat = bootstat-mu;
ci = ci-mu;
figure
histogram(bootstat,"Normalization","cdf")
hold on
yline(alpha, "Color","#D95319")
yline(1-alpha, "Color","#D95319")
xline(ci(1), "Color","#D95319")
xline(ci(2), "Color","#D95319")
The computed confidence interval does not aligne with the "cdf" histogram. But when I compute the interval using the following function, then it aligns as expected.
ci = prctile(bootstat, [alpha*100,(1-alpha)*100]);
Does anybody know, why is that the case?

採用された回答

Adam Danz
Adam Danz 2024 年 12 月 16 日
編集済み: Adam Danz 2024 年 12 月 16 日
You're using two different alpha values.
When you call bootci, you specify alpha as 0.05 or 5%.
When you call prctile, you're setting the p endpoints to 5% and 95% which is a 10% alpha value.
Instead,
ci = prctile(bootstat, [alpha/2,1-alpha/2]*100);
Remember, when alpha equal 5, that means the interval is the middle 95% of your data. The remaining 5% is split up on each side of the distribution with 2.5% on each side. So, the left bound will be at 2.5% and the right bound at 100-2.5 or 97.5%.
  1 件のコメント
Jakub
Jakub 2024 年 12 月 16 日
Thanks for clarifying! I see that I did not understand the meaning of alpha.

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2024 年 12 月 16 日
Because your prctile calculation should be
ci = prctile(bootstat, [(alpha/2)*100,(1-(alpha/2))*100]);

カテゴリ

Help Center および File ExchangeResampling Techniques についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by