public static int minimumSampleSizeForGivenDandMaximumRisk ( double d , double aLevel , double populationStd , int populationN ) { if ( populationN <= 0 || aLevel <= 0 || d <= 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double a = 1.0 - aLevel / 2.0 ; double Za = ContinuousDistributions . gaussInverseCdf ( a ) ; double V = Math . pow ( d / Za , 2 ) ; double Ssquare = populationStd * populationStd ; double minimumSampleN = ( Ssquare / V ) * ( 1.0 / ( 1.0 + Ssquare / ( populationN * V ) ) ) ; /* double minimumSampleN=populationN/( 1.0+populationN*pow(d/(Za*populationStd),2) ); */ return ( int ) Math . ceil ( minimumSampleN ) ; }
Returns the minimum required sample size when we set a predefined limit d and a maximum probability Risk a for finite population size