function(Npop, nsamp, ne, LBalpha)
{
# a bisection routine to find a lower 1-alpha confidence bound for Ne, the number of population items in error. Population size Npop, SRS size nsamp, ne = number of sample items in error.
if(ne == 0) return(0) else {
Na <- ne
Pa <- (1 - phyper(ne - 1, Na, Npop - Na, nsamp))
if(Pa >= LBalpha)
return(ne)
else {
Nb <- Npop
Pb <- 1
while((Nb - Na) > 1) {
Nnew <- trunc((Nb + Na)/2)
Pnew <- (1 - phyper(ne - 1, Nnew, Npop - Nnew, nsamp))
if(Pnew >= LBalpha) {
Nb <- Nnew
Pb <- Pnew
}
else {
Na <- Nnew
Pa <- Pnew
}
}
if(Pa >= LBalpha)
return(Na)
else return(Nb)
}
}
}