/** * Create a new F-distribution with the given degrees of freedom. * * @param numeratorDegreesOfFreedom numerator degrees of freedom * @param denominatorDegreesOfFreedom denominator degrees of freedom * @return a new F-distribution */ public FDistribution createFDistribution( double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom) { return new FDistributionImpl(numeratorDegreesOfFreedom, denominatorDegreesOfFreedom); }
final double denominatorDF = getDenominatorDegreesOfFreedom(); final double numeratorDF = getNumeratorDegreesOfFreedom(); final double denomDFMinusTwo = denominatorDF - 2;
/** * Create a F distribution using the given degrees of freedom and inverse cumulative probability accuracy. * @param numeratorDegreesOfFreedom the numerator degrees of freedom. * @param denominatorDegreesOfFreedom the denominator 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 FDistributionImpl(double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom, double inverseCumAccuracy) { super(); setNumeratorDegreesOfFreedomInternal(numeratorDegreesOfFreedom); setDenominatorDegreesOfFreedomInternal(denominatorDegreesOfFreedom); solverAbsoluteAccuracy = inverseCumAccuracy; }
/** * Create a F distribution using the given degrees of freedom. * @param numeratorDegreesOfFreedom the numerator degrees of freedom. * @param denominatorDegreesOfFreedom the denominator degrees of freedom. */ public FDistributionImpl(double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom) { super(); setNumeratorDegreesOfFreedom(numeratorDegreesOfFreedom); setDenominatorDegreesOfFreedom(denominatorDegreesOfFreedom); }
/** * Modify the denominator degrees of freedom. * @param degreesOfFreedom the new denominator degrees of freedom. * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not * positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) { setDenominatorDegreesOfFreedomInternal(degreesOfFreedom); }
/** * Modify the numerator degrees of freedom. * @param degreesOfFreedom the new numerator degrees of freedom. * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not * positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) { setNumeratorDegreesOfFreedomInternal(degreesOfFreedom); }
/** * 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) { return getDenominatorDegreesOfFreedom() / (getDenominatorDegreesOfFreedom() - 2.0); }
/** * Modify the denominator degrees of freedom. * @param degreesOfFreedom the new denominator degrees of freedom. * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not * positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) { setDenominatorDegreesOfFreedomInternal(degreesOfFreedom); }
/** * Modify the numerator degrees of freedom. * @param degreesOfFreedom the new numerator degrees of freedom. * @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not * positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) { setNumeratorDegreesOfFreedomInternal(degreesOfFreedom); }
/** * Returns the mean of the distribution. * * For denominator degrees of freedom parameter <code>b</code>, * the mean is * <ul> * <li>if <code>b > 2</code> then <code>b / (b - 2)</code></li> * <li>else <code>undefined</code> * </ul> * * @return the mean * @since 2.2 */ public double getNumericalMean() { final double denominatorDF = getDenominatorDegreesOfFreedom(); if (denominatorDF > 2) { return denominatorDF / (denominatorDF - 2); } return Double.NaN; }
/** * Generates a random value from the {@link FDistributionImpl F Distribution}. * This implementation uses {@link #nextInversionDeviate(ContinuousDistribution) inversion} * to generate random values. * * @param numeratorDf the numerator degrees of freedom of the F distribution * @param denominatorDf the denominator degrees of freedom of the F distribution * @return random value sampled from the F(numeratorDf, denominatorDf) distribution * @throws MathException if an error occurs generating the random value * @since 2.2 */ public double nextF(double numeratorDf, double denominatorDf) throws MathException { return nextInversionDeviate(new FDistributionImpl(numeratorDf, denominatorDf)); }
/** * Create a F distribution using the given degrees of freedom and inverse cumulative probability accuracy. * @param numeratorDegreesOfFreedom the numerator degrees of freedom. * @param denominatorDegreesOfFreedom the denominator 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 FDistributionImpl(double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom, double inverseCumAccuracy) { super(); setNumeratorDegreesOfFreedomInternal(numeratorDegreesOfFreedom); setDenominatorDegreesOfFreedomInternal(denominatorDegreesOfFreedom); solverAbsoluteAccuracy = inverseCumAccuracy; }
/** * For this distribution, X, this method returns P(X < x). * * The implementation of this method is based on: * <ul> * <li> * <a href="http://mathworld.wolfram.com/F-Distribution.html"> * F-Distribution</a>, equation (4).</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 { double n = getNumeratorDegreesOfFreedom(); double m = getDenominatorDegreesOfFreedom(); ret = Beta.regularizedBeta((n * x) / (m + n * x), 0.5 * n, 0.5 * m); } return ret; }
/** * {@inheritDoc}<p> * This implementation uses the * {@link org.apache.commons.math.distribution.FDistribution * commons-math F Distribution implementation} to estimate the exact * p-value, using the formula<pre> * p = 1 - cumulativeProbability(F)</pre> * where <code>F</code> is the F value and <code>cumulativeProbability</code> * is the commons-math implementation of the F distribution.</p> */ public double anovaPValue(Collection<double[]> categoryData) throws IllegalArgumentException, MathException { AnovaStats a = anovaStats(categoryData); FDistribution fdist = new FDistributionImpl(a.dfbg, a.dfwg); return 1.0 - fdist.cumulativeProbability(a.F); }
/** * {@inheritDoc}<p> * This implementation uses the * {@link org.apache.commons.math.distribution.FDistribution * commons-math F Distribution implementation} to estimate the exact * p-value, using the formula<pre> * p = 1 - cumulativeProbability(F)</pre> * where <code>F</code> is the F value and <code>cumulativeProbability</code> * is the commons-math implementation of the F distribution.</p> */ public double anovaPValue(Collection categoryData) throws IllegalArgumentException, MathException { AnovaStats a = anovaStats(categoryData); FDistribution fdist = new FDistributionImpl(a.dfbg, a.dfwg); return 1.0 - fdist.cumulativeProbability(a.F); }
/** * {@inheritDoc}<p> * This implementation uses the * {@link org.apache.commons.math.distribution.FDistribution * commons-math F Distribution implementation} to estimate the exact * p-value, using the formula<pre> * p = 1 - cumulativeProbability(F)</pre> * where <code>F</code> is the F value and <code>cumulativeProbability</code> * is the commons-math implementation of the F distribution.</p> */ public double anovaPValue(Collection<double[]> categoryData) throws IllegalArgumentException, MathException { AnovaStats a = anovaStats(categoryData); FDistribution fdist = new FDistributionImpl(a.dfbg, a.dfwg); return 1.0 - fdist.cumulativeProbability(a.F); }