static double sf()

in commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistribution.java [136:177]


        static double sf(double x, int n) {
            final double p = sfExact(x, n);
            if (p >= 0) {
                return p;
            }

            // The computation is divided based on the x-n plane.
            final double nxx = n * x * x;
            if (n <= N140) {
                // 10 decimal digits of precision

                // nx^2 < 4 use 1 - CDF(x).
                if (nxx < NXX_0_754693) {
                    // Durbin matrix (MTW)
                    return 1 - durbinMTW(x, n);
                }
                if (nxx < NXX_4) {
                    // Pomeranz
                    return 1 - pomeranz(x, n);
                }
                // Miller approximation: 2 * one-sided D+ computation
                return 2 * One.sf(x, n);
            }
            // n > 140
            if (nxx >= NXX_2_2) {
                // 6 decimal digits of precision

                // Miller approximation: 2 * one-sided D+ computation
                return 2 * One.sf(x, n);
            }
            // nx^2 < 2.2 use 1 - CDF(x).
            // 5 decimal digits of precision (for n < 200000)

            // nx^1.5 <= 1.4
            if (n <= N_100000 && n * Math.pow(x, 1.5) < NX32_1_4) {
                // Durbin matrix (MTW)
                return 1 - durbinMTW(x, n);
            }
            // Pelz-Good, algorithm modified to sum negative terms from 1 for the SF.
            // (precision increases with n)
            return pelzGood(x, n);
        }