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));endsum(g)/Nans = 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));endsum(g)/Nans = 0.9900
Any idea of why this happens? Is there a better way to calculate the confidence interval in this case?
Thanks in advance
Best Answer