/** * Construct a ChiSquareTestImpl */ public ChiSquareTestImpl() { this(new ChiSquaredDistributionImpl(1.0)); }
/** * Returns the mean of the distribution. * * For <code>k</code> degrees of freedom, the mean is * <code>k</code> * * @return the mean * @since 2.2 */ public double getNumericalMean() { return getDegreesOfFreedom(); }
/** * 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()); }
/** * Create a Chi-Squared distribution with the given degrees of freedom. * @param df degrees of freedom. * @param g the underlying gamma distribution used to compute probabilities. * @since 1.2 * @deprecated as of 2.1 (to avoid possibly inconsistent state, the * "GammaDistribution" will be instantiated internally) */ @Deprecated public ChiSquaredDistributionImpl(double df, GammaDistribution g) { super(); setGammaInternal(g); setDegreesOfFreedomInternal(df); solverAbsoluteAccuracy = DEFAULT_INVERSE_ABSOLUTE_ACCURACY; }
public static double criticalVal(int hashCount, double alpha) { ChiSquaredDistributionImpl d = new ChiSquaredDistributionImpl(hashCount - 1); try { return d.inverseCumulativeProbability(1 - alpha); } catch (MathException e) { return Double.MIN_VALUE; } }
/** * Modify the degrees of freedom. * @param degreesOfFreedom the new degrees of freedom. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setDegreesOfFreedom(double degreesOfFreedom) { setDegreesOfFreedomInternal(degreesOfFreedom); } /**
/** * Modify the underlying gamma distribution. The caller is responsible for * insuring the gamma distribution has the proper parameter settings. * @param g the new distribution. * @since 1.2 made public * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setGamma(GammaDistribution g) { setGammaInternal(g); } /**
/** * For this disbution, X, this method returns P(X < x). * @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 { return getGamma().cumulativeProbability(x); }
/** * Create a Chi-Squared distribution with the given degrees of freedom. * @param df degrees of freedom. * @param g the underlying gamma distribution used to compute probabilities. * @since 1.2 * @deprecated as of 2.1 (to avoid possibly inconsistent state, the * "GammaDistribution" will be instantiated internally) */ @Deprecated public ChiSquaredDistributionImpl(double df, GammaDistribution g) { super(); setGammaInternal(g); setDegreesOfFreedomInternal(df); solverAbsoluteAccuracy = DEFAULT_INVERSE_ABSOLUTE_ACCURACY; }
/** * Modify the degrees of freedom. * @param degreesOfFreedom the new degrees of freedom. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setDegreesOfFreedom(double degreesOfFreedom) { setDegreesOfFreedomInternal(degreesOfFreedom); } /**
/** * Modify the underlying gamma distribution. The caller is responsible for * insuring the gamma distribution has the proper parameter settings. * @param g the new distribution. * @since 1.2 made public * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setGamma(GammaDistribution g) { setGammaInternal(g); } /**
/** * Access the degrees of freedom. * @return the degrees of freedom. */ public double getDegreesOfFreedom() { return getGamma().getAlpha() * 2.0; }
/** * Construct a ChiSquareTestImpl */ public ChiSquareTestImpl() { this(new ChiSquaredDistributionImpl(1.0)); }
/** * Returns the variance of the distribution. * * For <code>k</code> degrees of freedom, the variance is * <code>2 * k</code> * * @return the variance * @since 2.2 */ public double getNumericalVariance() { return 2*getDegreesOfFreedom(); } }
/** * 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; }
/** * 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 degrees of freedom. * @param degreesOfFreedom the new degrees of freedom. */ public void setDegreesOfFreedom(double degreesOfFreedom) { getGamma().setAlpha(degreesOfFreedom / 2.0); }
/** * Create a new chi-square distribution with the given degrees of freedom. * * @param degreesOfFreedom degrees of freedom * @return a new chi-square distribution */ public ChiSquaredDistribution createChiSquareDistribution( final double degreesOfFreedom) { return new ChiSquaredDistributionImpl(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 */ @Override protected double getInitialDomain(double p) { // NOTE: chi squared is skewed to the left // NOTE: therefore, P(X < μ) > .5 double ret; if (p < .5) { // use 1/2 mean ret = getDegreesOfFreedom() * .5; } else { // use mean ret = getDegreesOfFreedom(); } 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; }