Example usage for org.apache.commons.math.distribution Distribution cumulativeProbability

List of usage examples for org.apache.commons.math.distribution Distribution cumulativeProbability

Introduction

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

Prototype

double cumulativeProbability(double x) throws MathException;

Source Link

Document

For a random variable X whose values are distributed according to this distribution, this method returns P(X ≤ x).

Usage

From source file:org.renjin.Distributions.java

/**
 *
 * Calculates the value of the cumulative distribution function
 *
 * @param dist the distribution/*from  w w w . ja  v a2 s. co m*/
 * @param q the value
 * @param lowerTail if true, return the value P(x < q), otherwise P(x > q)
 * @param logP  if true, return the natural logarithm of the probability
 * @return  the probability that the random variable will take the value less than (greater than)
 * {@code q}
 */
private static double p(Distribution dist, double q, boolean lowerTail, boolean logP) {
    double p;
    try {
        p = dist.cumulativeProbability(q);
    } catch (MathException e) {
        return Double.NaN;
    } catch (MathRuntimeException e) {
        return Double.NaN;
    }
    if (!lowerTail) {
        p = 1.0 - p;
    }
    if (logP) {
        p = Math.log(p);
    }

    return p;
}

From source file:yabby.math.distributions.ParametricDistribution.java

/**
 * For this distribution, X, this method returns x such that P(X &lt; x) = p.
 *
 * @param p the cumulative probability./*from   w ww .j av  a2s .  c  o  m*/
 * @return x.
 * @throws MathException if the inverse cumulative probability can not be
 *                       computed due to convergence or other numerical errors.
 */
//@Override
public double inverseCumulativeProbability(final double p) throws MathException {
    final org.apache.commons.math.distribution.Distribution dist = getDistribution();
    if (dist instanceof ContinuousDistribution) {
        return ((ContinuousDistribution) dist).inverseCumulativeProbability(p);
    } else if (dist instanceof IntegerDistribution) {
        return dist.cumulativeProbability(p);
    }
    return 0.0;
}