Example usage for org.apache.commons.math.distribution NormalDistribution inverseCumulativeProbability

List of usage examples for org.apache.commons.math.distribution NormalDistribution inverseCumulativeProbability

Introduction

In this page you can find the example usage for org.apache.commons.math.distribution NormalDistribution inverseCumulativeProbability.

Prototype

double inverseCumulativeProbability(double p) throws MathException;

Source Link

Document

For this distribution, X, this method returns x such that P(X < x) = p.

Usage

From source file:geogebra.kernel.statistics.AlgoInverseNormal.java

protected final void compute() {

    if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined()) {
        double param = a.getDouble();
        double param2 = b.getDouble();
        double val = c.getDouble();
        try {/*from   w ww.ja va  2 s .  c om*/
            NormalDistribution dist = getNormalDistribution(param, param2);
            num.setValue(dist.inverseCumulativeProbability(val));

        } catch (Exception e) {
            num.setUndefined();
        }
    } else
        num.setUndefined();
}

From source file:geogebra.common.kernel.statistics.AlgoInverseNormal.java

@Override
public final void compute() {

    if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined()) {
        double param = a.getDouble();
        double param2 = b.getDouble();
        double val = c.getDouble();
        try {//from  w  ww  .j a  v  a2 s  .  c  o  m
            NormalDistribution dist = getNormalDistribution(param, param2);
            num.setValue(dist.inverseCumulativeProbability(val));

        } catch (Exception e) {
            num.setUndefined();
        }
    } else
        num.setUndefined();
}

From source file:datafu.pig.stats.WilsonBinConf.java

/**
 * @param x The number of positive (success) outcomes
 * @param n The number of observations// w w  w  . j a  va2s.  c om
 * @return The (lower,upper) confidence interval
 */
public Tuple binconf(Long x, Long n) throws IOException {
    NormalDistribution normalDist = new NormalDistributionImpl();

    if (x == null || n == null)
        return null;
    if (x < 0 || n < 0)
        throw new IllegalArgumentException("non-negative values expected");
    if (x > n)
        throw new IllegalArgumentException("invariant violation: number of successes > number of obs");
    if (n == 0)
        return tupleFactory.newTuple(ImmutableList.of(Double.valueOf(0), Double.valueOf(0)));

    try {
        double zcrit = -1.0 * normalDist.inverseCumulativeProbability(alpha / 2);
        double z2 = zcrit * zcrit;
        double p = x / (double) n;

        double a = p + z2 / 2 / n;
        double b = zcrit * Math.sqrt((p * (1 - p) + z2 / 4 / n) / n);
        double c = (1 + z2 / n);

        double lower = (a - b) / c;
        double upper = (a + b) / c;

        // Add corrections for when x is very close to n.  This improves the estimates.
        // For more info on wilson binomial confidence interval, see paper:
        // L.D. Brown, T.T. Cai and A. DasGupta, Interval estimation for a binomial proportion (with discussion), 
        //   _Statistical Science,_*16*:101-133, 2001. 
        // http://www-stat.wharton.upenn.edu/~tcai/paper/Binomial-StatSci.pdf

        if (x == 1)
            lower = -Math.log(1 - alpha) / n;
        if (x == (n - 1))
            upper = 1 + Math.log(1 - alpha) / n;

        return tupleFactory.newTuple(ImmutableList.of(lower, upper));
    } catch (MathException e) {
        throw new IOException("math error", e);
    }
}

From source file:org.apache.mahout.knn.generate.NormalTest.java

@Test
public void testSample() throws MathException {
    double[] data = new double[10001];
    Sampler<Double> sampler = new Normal();
    for (int i = 0; i < 10001; i++) {
        data[i] = sampler.sample();/* w  w  w .  ja  v  a 2s . c o  m*/
    }
    Arrays.sort(data);

    NormalDistribution reference = new NormalDistributionImpl();

    assertEquals("Median", reference.inverseCumulativeProbability(0.5), data[5000], 0.04);
}

From source file:org.bdval.MaqciiHelper.java

private double stouffer(final double[] pval) {
    double rval = 1.0;
    final NormalDistribution normd = new NormalDistributionImpl();
    normd.setMean(0);//w w  w .ja v  a 2s.com
    normd.setStandardDeviation(1);
    final int size = pval.length;
    final double[] z = new double[size];
    double zCombine = 0;

    for (int i = 0; i < size; i++) {
        try {
            z[i] = normd.inverseCumulativeProbability(pval[i]);
        } catch (MathException e) {
            LOG.warn("Error calculating probability", e);
        }
        zCombine += z[i];
    }
    zCombine /= Math.sqrt(size);

    try {
        rval = normd.cumulativeProbability(zCombine);
    } catch (MathException e) {
    }

    return rval;
}