Confidence interval using binofit
Show older comments
Hello all,
I was doing a test using binofit to calculate the confidence interval for a binomial distribution. I found that the confidence interval corresponds to the desired confidence level only when p is not very small. When p is small the obtained confidence level is higher than desired.
For a 95% I tried:
N=1000;
g=zeros(N,1);
Nb = 1000;
p = 1/5;
for n=1:N
x=binornd(Nb,p);
[phat,pci]=binofit(x,Nb);
g(n)= (p>pci(1)) && (p<pci(2));
end
sum(g)/N
ans =
0.9570
However, if p is decreased by a factor of 100:
N=1000;
g=zeros(N,1);
Nb = 1000;
p = 1/500;
for n=1:N
x=binornd(Nb,p);
[phat,pci]=binofit(x,Nb);
g(n)= (p>pci(1)) && (p<pci(2));
end
sum(g)/N
ans =
0.9900
Any idea of why this happens? Is there a better way to calculate the confidence interval in this case?
Thanks in advance
Accepted Answer
More Answers (1)
Javier
on 14 Sep 2012
0 votes
Categories
Find more on Binomial Distribution in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!