# Algorithm Providing Ordered Integer Sequences for Sampling with Replacement Confidence Intervals
## 2 Constructing a CI  
In many ways, [PERSON]'s CI [5], derived under the assumption of an infinite population, is a reference example of a CI. Anticipating the results communicated here, a CI for a sampled with replacement variable (\(x\) out of \(m\)) should be seen as the outcome of an algorithm rather than of a simple mathematical formula, and the outcome of an such algorithm should be a series of numbers, indexed from 0 to \(m\): \(N_{0}\), \(N_{1}\),..., \(N_{m}\). It is proposed that, by symmetry, a CI should be constructed with these numbers for \(x\) out of \(m\) as \([N_{x},m-N_{m-x}]\). Let us take an example with [PERSON]'s CI [5]. Let \(z_{\alpha}=\Phi(1-\alpha/2)\), where \(\Phi\) is the cumulative function of the normal distribution. For \(\alpha=0.05\), \(z_{\alpha}\) is about 1.95996. A Wald CI will be calculated as in Equation (2):  
\[CI_{W}(x;m,\alpha)=x\pm z_{\alpha}\sqrt{x(m-x)/m} \tag{2}\]  
It is nonsensical to have boundaries smaller than 0 or larger than \(m\). Furthermore, any non-integer value of the boundary makes no difference since \(x\) takes only integer values. Table 1 lists the CIs for variables (\(x\) in Table 1) with nonnegative integers as boundaries calculated with Equation (2) and provided along with their true coverage probabilities. \begin{table}
\begin{tabular}{c c c c c} \hline \hline \(x\) & \(CI_{W}\) & \(CI_{I}\) & **Ordered Integer Sequences** & **Coverage** \\ \hline
1 & \(\pm 1.9\) & \([0,2]\) & \(0=N_{1},10-N_{10-1}=2\) & 92.98\% \\ \hline
2 & \(\pm 2.5\) & \([0,4]\) & \(0=N_{2},10-N_{10-2}=4\) & 96.72\% \\ \hline
3 & \(\pm 2.8\) & \([1,5]\) & \(1=N_{3},10-N_{10-3}=5\) & 92.44\% \\ \hline
4 & \(\pm 3.0\) & \([1,7]\) & \(1=N_{4},10-N_{10-4}=7\) & 98.17\% \\ \hline
5 & \(\pm 3.1\) & \([2,8]\) & \(2=N_{5},10-N_{10-5}=8\) & 97.85\% \\ \hline
6 & \(\pm 3.0\) & \([3,9]\) & \(3=N_{6},10-N_{10-6}=9\) & 98.17\% \\ \hline
7 & \(\pm 2.8\) & \([5,9]\) & \(5=N_{7},10-N_{10-7}=9\) & 92.44\% \\ \hline
8 & \(\pm 2.5\) & \([6,10]\) & \(6=N_{8},10-N_{10-8}=10\) & 96.72\% \\ \hline
9 & \(\pm 1.9\) & \([8,10]\) & \(8=N_{9},10-N_{10-9}=10\) & 92.98\% \\ \hline \hline \end{tabular}
\end{table} 
Table 1: From [PERSON]’s CI to ordered integer sequences (\(m=10\) and \(\alpha=5\%\)). One should notice the symmetry in the intervals provided in Table 1. However, the solution provided in Table 1 is not optimal. Thus,  
* CIs provided in Table 1 are not optimal; 2, 3, 5, 6, and 8 instead of 1, 2, 4, 5, and 7 provide better estimates;
* If it is optimal to provide an at least \(1-\alpha\) coverage, then \(CI(1,10,0.05)\) should be \([0,3]\) instead of \([0,2]\) with a coverage of 98.72% instead of 92.98%; \(CI(3,10,0.05)\) should be \([0,5]\) or \([1,6]\) instead of \([1,5]\) with coverage of 95.27% and 96.12% instead of 92.44%;
* If it is optimal to provide an at most \(1-\alpha\) coverage, then \(CI(2,10,0.05)\) should be \([0,3]\) instead of \([0,4]\) with a coverage of 87.91% instead of 97.72%; \(CI(4,10,0.05)\) should be \([0,6]\) instead of [1,7] with a coverage of 94.52% or \([1,6]\) with a coverage of 93.92% instead of 97.72%;
* As can be observed, imposing a single rule (such as \"at least\" or \"at most\") is not enough; see alternatives for \(CI(3,10,0.05)\): \([0,5]\) has a coverage of 95.27% and \([1,6]\) has a coverage of 96.12% or alternatives for \(CI(4,10,0.05)\): \([0,6]\) has a coverage of 94.52% and \([1,6]\) has a coverage of 93.92%;
* Being closest to the imposed coverage but at least equal (or at most equal) to it seems a reasonable criterion but does not work all the time; thus, for it to be the closest to the imposed coverage but at most equal, \(CI(3,10,0.05)\) should be \([1,5]\) with a coverage of 92.44% and \(CI(4,10,0.05)\) should be \([0,6]\) with a coverage of 94.52%. However, since the left boundary of \(CI(3,10,0.05)\) is 1, another common sense rule says that the left boundary of \(CI(4,10,0.05)\) should be at least 1. To summarize, there is no unique recipe for an ideal CI for binomial distribution.