public TwoResult test()

in commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/KolmogorovSmirnovTest.java [575:620]


    public TwoResult test(double[] x, double[] y) {
        final int n = checkArrayLength(x);
        final int m = checkArrayLength(y);
        PValueMethod method = pValueMethod;
        final int[] sign = {0};
        final long[] tiesD = {0, 0};

        final double[] sx = x.clone();
        final double[] sy = y.clone();
        final long dnm = computeIntegralKolmogorovSmirnovStatistic(sx, sy, sign, tiesD);

        // Compute p-value. Note that the p-value is not invalidated by ties; it is the
        // D statistic that could be invalidated by resolution of the ties. So compute
        // the exact p even if ties are present.
        if (method == PValueMethod.AUTO) {
            // Use exact for small samples
            method = Math.max(n, m) < LARGE_SAMPLE ?
                PValueMethod.EXACT :
                PValueMethod.ASYMPTOTIC;
        }
        final int gcd = ArithmeticUtils.gcd(n, m);
        final double d = computeD(dnm, n, m, gcd);
        final boolean significantTies = tiesD[1] > dnm;
        final double d2 = significantTies ? computeD(tiesD[1], n, m, gcd) : d;

        final double p;
        double p2;

        // Allow bootstrap estimation of the p-value
        if (method == PValueMethod.ESTIMATE) {
            p = estimateP(sx, sy, dnm);
            p2 = Double.NaN;
        } else {
            final boolean exact = method == PValueMethod.EXACT;
            p = p2 = twoSampleP(dnm, n, m, gcd, d, exact);
            if (significantTies) {
                // Compute the upper bound on D.
                // The p-value is also computed. The alternative is to save the options
                // in the result with (upper dnm, n, m) and compute it on-demand.
                // Note detection of whether the exact P computation is possible is based on
                // n and m, thus this will use the same computation.
                p2 = twoSampleP(tiesD[1], n, m, gcd, d2, exact);
            }
        }
        return new TwoResult(d, sign[0], p, significantTies, d2, p2);
    }