/** * Create a Chi-Squared distribution with the given degrees of freedom. * @param df degrees of freedom. */ public ChiSquaredDistributionImpl(double df) { this(df, new GammaDistributionImpl(df / 2.0, 2.0)); }
/** * Create a new gamma distribution with the given alpha and beta values. * @param alpha the shape parameter. * @param beta the scale parameter. * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) * @since 2.1 */ public GammaDistributionImpl(double alpha, double beta, double inverseCumAccuracy) { super(); setAlphaInternal(alpha); setBetaInternal(beta); solverAbsoluteAccuracy = inverseCumAccuracy; }
/** * Modify the shape parameter, alpha. * @param alpha the new shape parameter. * @throws IllegalArgumentException if <code>alpha</code> is not positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setAlpha(double alpha) { setAlphaInternal(alpha); }
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @deprecated */ public double density(Double x) { return density(x.doubleValue()); }
/** * Modify the scale parameter, beta. * @param newBeta the new scale parameter. * @throws IllegalArgumentException if <code>newBeta</code> is not positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setBeta(double newBeta) { setBetaInternal(newBeta); }
/** * Modify the shape parameter, alpha. * @param alpha the new shape parameter. * @throws IllegalArgumentException if <code>alpha</code> is not positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setAlpha(double alpha) { setAlphaInternal(alpha); }
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @deprecated */ @Deprecated public double density(Double x) { return density(x.doubleValue()); }
/** * Modify the scale parameter, beta. * @param newBeta the new scale parameter. * @throws IllegalArgumentException if <code>newBeta</code> is not positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setBeta(double newBeta) { setBetaInternal(newBeta); }
/** * Create a Chi-Squared distribution with the given degrees of freedom. * @param df degrees of freedom. */ public ChiSquaredDistributionImpl(double df) { this(df, new GammaDistributionImpl(df / 2.0, 2.0)); }
/** * Create a new gamma distribution with the given alpha and beta values. * @param alpha the shape parameter. * @param beta the scale parameter. * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) * @since 2.1 */ public GammaDistributionImpl(double alpha, double beta, double inverseCumAccuracy) { super(); setAlphaInternal(alpha); setBetaInternal(beta); solverAbsoluteAccuracy = inverseCumAccuracy; }
/** * Access the domain value upper bound, based on <code>p</code>, used to * bracket a CDF root. This method is used by * {@link #inverseCumulativeProbability(double)} to find critical values. * * @param p the desired probability for the critical value * @return domain value upper bound, i.e. * P(X < <i>upper bound</i>) > <code>p</code> */ protected double getDomainUpperBound(double p) { // TODO: try to improve on this estimate // NOTE: gamma is skewed to the left // NOTE: therefore, P(X < μ) > .5 double ret; if (p < .5) { // use mean ret = getAlpha() * getBeta(); } else { // use max value ret = Double.MAX_VALUE; } return ret; }
/** * Create a new gamma distribution the given shape and scale parameters. * * @param alpha the shape parameter * @param beta the scale parameter * @return a new gamma distribution */ public GammaDistribution createGammaDistribution( double alpha, double beta) { return new GammaDistributionImpl(alpha, beta); }
/** * Access the initial domain value, based on <code>p</code>, used to * bracket a CDF root. This method is used by * {@link #inverseCumulativeProbability(double)} to find critical values. * * @param p the desired probability for the critical value * @return initial domain value */ protected double getInitialDomain(double p) { // TODO: try to improve on this estimate // Gamma is skewed to the left, therefore, P(X < μ) > .5 double ret; if (p < .5) { // use 1/2 mean ret = getAlpha() * getBeta() * .5; } else { // use mean ret = getAlpha() * getBeta(); } return ret; } }
/** * Create a Chi-Squared distribution with the given degrees of freedom. * @param df degrees of freedom. */ public ChiSquaredDistributionImpl(double df) { this(df, new GammaDistributionImpl(df / 2.0, 2.0)); }
/** * For this disbution, X, this method returns P(X < x). * * The implementation of this method is based on: * <ul> * <li> * <a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html"> * Chi-Squared Distribution</a>, equation (9).</li> * <li>Casella, G., & Berger, R. (1990). <i>Statistical Inference</i>. * Belmont, CA: Duxbury Press.</li> * </ul> * * @param x the value at which the CDF is evaluated. * @return CDF for this distribution. * @throws MathException if the cumulative probability can not be * computed due to convergence or other numerical errors. */ public double cumulativeProbability(double x) throws MathException{ double ret; if (x <= 0.0) { ret = 0.0; } else { ret = Gamma.regularizedGammaP(getAlpha(), x / getBeta()); } return ret; }
/** * Create a Chi-Squared distribution with the given degrees of freedom and * inverse cumulative probability accuracy. * @param df degrees of freedom. * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) * @since 2.1 */ public ChiSquaredDistributionImpl(double df, double inverseCumAccuracy) { super(); gamma = new GammaDistributionImpl(df / 2.0, 2.0); setDegreesOfFreedomInternal(df); solverAbsoluteAccuracy = inverseCumAccuracy; }
/** * Create a Chi-Squared distribution with the given degrees of freedom and * inverse cumulative probability accuracy. * @param df degrees of freedom. * @param inverseCumAccuracy the maximum absolute error in inverse cumulative probability estimates * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) * @since 2.1 */ public ChiSquaredDistributionImpl(double df, double inverseCumAccuracy) { super(); gamma = new GammaDistributionImpl(df / 2.0, 2.0); setDegreesOfFreedomInternal(df); solverAbsoluteAccuracy = inverseCumAccuracy; }