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

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

Introduction

In this page you can find the example usage for org.apache.commons.math.distribution ContinuousDistribution 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:org.renjin.Distributions.java

/**
 * Calculates the value of the inverse cumulative probability function according to standard R arguments.
 *
 * @param dist the continuous distribution
 * @param p the probability//  w  w w. j  a v a2 s.  c om
 * @param lowerTail
 * @param logP if true, interpret {@code p} as the natural logarithm of the probability
 * @return the value fo
 */
private static double q(ContinuousDistribution dist, double p, boolean lowerTail, boolean logP) {
    if (logP) {
        p = Math.exp(p);
    }
    double q = 0;
    try {
        q = dist.inverseCumulativeProbability(p);
    } catch (IllegalArgumentException e) {
        return Double.NaN;
    } catch (MathException e) {
        return Double.NaN;
    } catch (MathRuntimeException e) {
        return Double.NaN;
    }
    if (!lowerTail) {
        q = -q;
    }
    return q;
}