public static double approximateUpperBoundOnP ( final long n , final long k , final double numStdDevs ) { checkInputs ( n , k ) ; if ( n == 0 ) { return 1.0 ; } // the coin was never flipped, so we know nothing else if ( k == n ) { return 1.0 ; } else if ( k == ( n - 1 ) ) { return ( exactUpperBoundOnPForKequalsNminusOne ( n , deltaOfNumStdevs ( numStdDevs ) ) ) ; } else if ( k == 0 ) { return ( exactUpperBoundOnPForKequalsZero ( n , deltaOfNumStdevs ( numStdDevs ) ) ) ; } else { final double x = abramowitzStegunFormula26p5p22 ( n - k , k + 1 , numStdDevs ) ; return ( 1.0 - x ) ; // which is p } }
Computes upper bound of approximate Clopper - Pearson confidence interval for a binomial proportion .