/** * Computes the two-sample Kolmogorov-Smirnov test statistic, \(D_{n,m}=\sup_x |F_n(x)-F_m(x)|\) * where \(n\) is the length of {@code x}, \(m\) is the length of {@code y}, \(F_n\) is the * empirical distribution that puts mass \(1/n\) at each of the values in {@code x} and \(F_m\) * is the empirical distribution of the {@code y} values. * * @param x first sample * @param y second sample * @return test statistic \(D_{n,m}\) used to evaluate the null hypothesis that {@code x} and * {@code y} represent samples from the same underlying distribution * @throws InsufficientDataException if either {@code x} or {@code y} does not have length at * least 2 * @throws NullArgumentException if either {@code x} or {@code y} is null */ public double kolmogorovSmirnovStatistic(double[] x, double[] y) { return integralKolmogorovSmirnovStatistic(x, y)/((double)(x.length * (long)y.length)); }
System.arraycopy(y, 0, combined, xLength, yLength); final EnumeratedRealDistribution dist = new EnumeratedRealDistribution(rng, combined); final long d = integralKolmogorovSmirnovStatistic(x, y); int greaterCount = 0; int equalCount = 0; curX = dist.sample(xLength); curY = dist.sample(yLength); curD = integralKolmogorovSmirnovStatistic(curX, curY); if (curD > d) { greaterCount++;
/** * Computes the two-sample Kolmogorov-Smirnov test statistic, \(D_{n,m}=\sup_x |F_n(x)-F_m(x)|\) * where \(n\) is the length of {@code x}, \(m\) is the length of {@code y}, \(F_n\) is the * empirical distribution that puts mass \(1/n\) at each of the values in {@code x} and \(F_m\) * is the empirical distribution of the {@code y} values. * * @param x first sample * @param y second sample * @return test statistic \(D_{n,m}\) used to evaluate the null hypothesis that {@code x} and * {@code y} represent samples from the same underlying distribution * @throws InsufficientDataException if either {@code x} or {@code y} does not have length at * least 2 * @throws NullArgumentException if either {@code x} or {@code y} is null */ public double kolmogorovSmirnovStatistic(double[] x, double[] y) { return integralKolmogorovSmirnovStatistic(x, y)/((double)(x.length * (long)y.length)); }
System.arraycopy(y, 0, combined, xLength, yLength); final EnumeratedRealDistribution dist = new EnumeratedRealDistribution(rng, combined); final long d = integralKolmogorovSmirnovStatistic(x, y); int greaterCount = 0; int equalCount = 0; curX = dist.sample(xLength); curY = dist.sample(yLength); curD = integralKolmogorovSmirnovStatistic(curX, curY); if (curD > d) { greaterCount++;