I am trying to follow the procedure of a Sandia Labs report found here to determine the required sample size, for various population sizes, with no replacement for a given confidence and reliability. The authors provide Mathematica code but I chose to write my own based on their procedure.
The procedure described on page 13 is “The second SNL technique can be extended for any number of defective units in the sample by using the CDF for the hypergeometric distribution. This extension is referred to as the third technique. To find the minimum n given a specific x required for given N, γ, and R, the following technique can be used. Note that D is (1 - R) N rounded to the nearest integer. For the hypergeometric distribution HyperDist(n, D, N), find the minimum n for which CDF(HyperDist(n, D, N), x) does not exceed γ”.
I believe I’m able to reproduce the corrected results in Tables 1 & 2 of the above report with my code below. There are columns labeled “INCORRECT” which I don’t plan to confirm. These tables however are based on observing zero failures in the sample taken while I would like to be able to specify an arbitrary number of x failures. But when I use an x value (number of failures) other than zero I get an error message. Can someone shed any insight into this ? Thanks.
My code is :
c=0.9; (* Confidence *)
r=0.9; (* Reliability *)
x=0; (* Number of failures in the sample *)
pop=10; (* Population size *)
n=0; (* Sample size, iterated *)
d=Round[(1-r)*pop]
gamma=1-c
Do[{
Label[iterate];
n=n+1;
dist=HypergeometricDistribution[n,d,pop];
cdf[z_]:=CDF[dist,z];
cdfvalue=N[cdf[x]];
If[cdfvalue>gamma,Goto[iterate],Print["Solution:"]];
Print["n = ",n];
Print["CDF[x] = ",cdfvalue];
Break[]},
{pop+2}]
HypergeometricDistribution
, the first parameter must be positive & <= the last, the second parameter must be between 0 and the last, inclusive. That's not happening when you get the error. $\endgroup$