Example usage for org.apache.commons.math3.distribution EnumeratedRealDistribution EnumeratedRealDistribution

List of usage examples for org.apache.commons.math3.distribution EnumeratedRealDistribution EnumeratedRealDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution EnumeratedRealDistribution EnumeratedRealDistribution.

Prototype

public EnumeratedRealDistribution(final double[] singletons, final double[] probabilities)
        throws DimensionMismatchException, NotPositiveException, MathArithmeticException,
        NotFiniteNumberException, NotANumberException 

Source Link

Document

Create a discrete distribution using the given probability mass function enumeration.

Usage

From source file:cz.cuni.mff.spl.evaluator.statistics.KolmogorovSmirnovTestFlag.java

/**
 * Estimates the <i>p-value</i> of a two-sample
 * <a href="http://en.wikipedia.org/wiki/Kolmogorov-Smirnov_test"> Kolmogorov-Smirnov test</a>
 * evaluating the null hypothesis that {@code x} and {@code y} are samples drawn from the same
 * probability distribution. This method estimates the p-value by repeatedly sampling sets of size
 * {@code x.length} and {@code y.length} from the empirical distribution of the combined sample.
 * When {@code strict} is true, this is equivalent to the algorithm implemented in the R function
 * {@code ks.boot}, described in <pre>
 * Jasjeet S. Sekhon. 2011. 'Multivariate and Propensity Score Matching
 * Software with Automated Balance Optimization: The Matching package for R.'
 * Journal of Statistical Software, 42(7): 1-52.
 * </pre>//  w  w  w.  j  a  v a 2  s.co  m
 * @param x first sample
 * @param y second sample
 * @param iterations number of bootstrap resampling iterations
 * @param strict whether or not the null hypothesis is expressed as a strict inequality
 * @return estimated p-value
 */
public double bootstrap(double[] x, double[] y, int iterations, boolean strict) {
    final int xLength = x.length;
    final int yLength = y.length;
    final double[] combined = new double[xLength + yLength];
    System.arraycopy(x, 0, combined, 0, xLength);
    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;
    double[] curX;
    double[] curY;
    long curD;
    for (int i = 0; i < iterations; i++) {
        curX = dist.sample(xLength);
        curY = dist.sample(yLength);
        curD = integralKolmogorovSmirnovStatistic(curX, curY);
        if (curD > d) {
            greaterCount++;
        } else if (curD == d) {
            equalCount++;
        }
    }
    return strict ? greaterCount / (double) iterations : (greaterCount + equalCount) / (double) iterations;
}