ciss.midp(p0, d, alpha, nMax=1e6)
alpha
)*100%
confidence interval, one finds the sample size $n$ as the solution
to $$\frac{1}{2} f(x;n,p_l) + \frac{1}{2} f(x;n,p_u) + (1 -
F(x;n,p_l)) + F(x-1;m,p_u) = \alpha$$
where $f(x;n,p)$ denotes the probability mass function (pmf) and
$F(x;n,p)$ the (cumulative) distribution function of the binomial
distribution with size $n$ and proportion $p$ evaluated at
$x$. The function then returns $\lceil n \rceil$. Note that
in this approach $(p_l,p_u) = p_0 \pm d$, which has to be a subset
of $(0,1)$. Another option would be to choose the lower and upper
independent specifically.
In the above, $x$ is found as the integer value, such that
$x/n$ is as close as possible to the hypothesized value p0
as possible.
An alternative approach to determine sample sizes based on the mid-p
approach is to manually find the sample size $n$ such that the
interval obtained by binom.midp
has a length less than
$2\cdot d$.
binom.midp
, ciss.binom
#Fosgate approach
ciss.midp(p0=0.2,alpha=0.05,d=0.05)
#Iterative increase of n using the general purpose function
ciss.binom( p0=0.2, alpha=0.05, ci.fun=binom.midp, d=0.05)
Run the code above in your browser using DataLab