MultinomialConfidenceIntervals - Simultaneous multinomial confidence intervals. Confidence intervals computed simultaneously on all cells using the method of Fitzpatrick and Scott (1987). This provides better estimates of the confidence intervals than the common (but erroneous) method where each cell is treated as an independent binomial variable. USAGE [p,boudaries] = MultinomialConfidenceIntervals(samples,alpha) samples list of numbers of samples in each cell alpha optional significance level (default = 0.05) p list of estimated cell probabilities boundaries confidence interval boudaries
0001 function [p,boundaries] = MultinomialConfidenceIntervals(samples,alpha) 0002 0003 %MultinomialConfidenceIntervals - Simultaneous multinomial confidence intervals. 0004 % 0005 % Confidence intervals computed simultaneously on all cells using the method of 0006 % Fitzpatrick and Scott (1987). This provides better estimates of the confidence 0007 % intervals than the common (but erroneous) method where each cell is treated 0008 % as an independent binomial variable. 0009 % 0010 % USAGE 0011 % 0012 % [p,boudaries] = MultinomialConfidenceIntervals(samples,alpha) 0013 % 0014 % samples list of numbers of samples in each cell 0015 % alpha optional significance level (default = 0.05) 0016 % 0017 % p list of estimated cell probabilities 0018 % boundaries confidence interval boudaries 0019 0020 % Copyright (C) 2004-2011 by Michaƫl Zugaro 0021 % 0022 % This program is free software; you can redistribute it and/or modify 0023 % it under the terms of the GNU General Public License as published by 0024 % the Free Software Foundation; either version 3 of the License, or 0025 % (at your option) any later version. 0026 0027 % Parameter checking and default values 0028 0029 if nargin < 1, 0030 error('Incorrect number of parameters (type ''help <a href="matlab:help MultinomialConfidenceIntervals">MultinomialConfidenceIntervals</a>'' for details).'); 0031 end 0032 0033 if nargin < 2 0034 alpha = 0.05; 0035 end 0036 0037 % Process 0038 0039 n = sum(samples); 0040 p = samples/n; 0041 0042 % There is a problem in the paper, so we cannot compute the intervals in the general case 0043 % Thus, the following code is commented out 0044 0045 % if alpha < 0.016, 0046 % alpha = alpha/2; 0047 % elseif alpha < 0.15, 0048 % log(sqrt(2*pi)*(1-alpha/6)) 0049 % x = sqrt(-4/9*log(sqrt(2*pi)*(1-alpha/6))); 0050 % alpha = 2*normcdf(x) 0051 % % alpha = 6*normcdf(3*norminv(alpha/2)/sqrt(8))-5; 0052 % else 0053 % error('Cannot compute confidence intervals for this alpha level'); 0054 % end 0055 % b = abs(norminv(alpha/2)/(2*sqrt(n))); 0056 0057 if alpha == 0.1, 0058 k = 1; 0059 elseif alpha == 0.05, 0060 k = 1.13; 0061 elseif alpha == 0.01, 0062 k = 1.40; 0063 else 0064 error('Cannot compute confidence intervals for this alpha level'); 0065 end 0066 0067 b = k/sqrt(n); 0068 boundaries = [max(p-b,0);min(p+b,1)];