/** * Generates a random value from the {@link ChiSquaredDistribution ChiSquare Distribution}. * * @param df the degrees of freedom of the ChiSquare distribution * @return random value sampled from the ChiSquare(df) distribution */ public double nextChiSquare(double df) { return new ChiSquaredDistribution(getRandomGenerator(), df, ChiSquaredDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample(); }
/** * Returns the intrinsic (Hardy-Weinberg proportions) p-Value, as described * in p64-69 of McDonald, J.H. 2009. Handbook of Biological Statistics * (2nd ed.). Sparky House Publishing, Baltimore, Maryland. * * <p> The probability returned is the tail probability beyond * {@link #g(double[], long[]) g(expected, observed)} * in the ChiSquare distribution with degrees of freedom two less than the * common length of {@code expected} and {@code observed}.</p> * * @param observed array of observed frequency counts * @param expected array of expected frequency counts * @return p-value * @throws NotPositiveException if {@code observed} has negative entries * @throws NotStrictlyPositiveException {@code expected} has entries that are * not strictly positive * @throws DimensionMismatchException if the array lengths do not match or * are less than 2. * @throws MaxCountExceededException if an error occurs computing the * p-value. */ public double gTestIntrinsic(final double[] expected, final long[] observed) throws NotPositiveException, NotStrictlyPositiveException, DimensionMismatchException, MaxCountExceededException { // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final ChiSquaredDistribution distribution = new ChiSquaredDistribution(null, expected.length - 2.0); return 1.0 - distribution.cumulativeProbability(g(expected, observed)); }
new ChiSquaredDistribution(null, expected.length - 1.0); return 1.0 - distribution.cumulativeProbability(chiSquare(expected, observed));
new ChiSquaredDistribution(null, expected.length - 1.0); return 1.0 - distribution.cumulativeProbability(g(expected, observed));
new ChiSquaredDistribution(null, (double) observed1.length - 1); return 1 - distribution.cumulativeProbability( gDataSetsComparison(observed1, observed2));
new ChiSquaredDistribution(null, (double) observed1.length - 1); return 1 - distribution.cumulativeProbability( chiSquareDataSetsComparison(observed1, observed2));
double df = ((double) counts.length -1) * ((double) counts[0].length - 1); final ChiSquaredDistribution distribution = new ChiSquaredDistribution(df); return 1 - distribution.cumulativeProbability(chiSquare(counts));
/** * @param df * degree of freedom * @return implementation of ChiSquaredDistribution for given degree of * freedom */ private ChiSquaredDistribution getChiSquaredDistribution(double df) { if (chisquared == null || chisquared.getDegreesOfFreedom() != df) { chisquared = new ChiSquaredDistribution(df); } return chisquared; }
/** * @param param * degrees of freedom * @return chi squared distribution */ protected ChiSquaredDistribution getChiSquaredDistribution(double param) { if (chisquared == null || chisquared.getDegreesOfFreedom() != param) { chisquared = new ChiSquaredDistribution(param); } return chisquared; }
/** * @return the p value for the most recent test. */ public double getPValue() { double cdf = new ChiSquaredDistribution(this.df).cumulativeProbability(this.chisq); return 1.0 - cdf; }
/** * @return the p value for the most recent test. */ public double getPValue() { double cdf = new ChiSquaredDistribution(this.df).cumulativeProbability(this.chisq); return 1.0 - cdf; }
/** * @param df * degree of freedom * @return implementation of ChiSquaredDistribution for given degree of * freedom */ ChiSquaredDistribution getChiSquaredDistribution(double df) { if (chisquared == null || chisquared.getDegreesOfFreedom() != df) { chisquared = new ChiSquaredDistribution(df); } return chisquared; }
/** * * @param df * @param testStatistic * @return */ public static double chiSquareTest(int df, double testStatistic) { ChiSquaredDistribution chi = new ChiSquaredDistribution(df); return chi.density(testStatistic); }
/** * Generates a random value from the {@link ChiSquaredDistribution ChiSquare Distribution}. * * @param df the degrees of freedom of the ChiSquare distribution * @return random value sampled from the ChiSquare(df) distribution */ public double nextChiSquare(double df) { return new ChiSquaredDistribution(getRandomGenerator(), df, ChiSquaredDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample(); }
/** * Generates a random value from the {@link ChiSquaredDistribution ChiSquare Distribution}. * * @param df the degrees of freedom of the ChiSquare distribution * @return random value sampled from the ChiSquare(df) distribution */ public double nextChiSquare(double df) { return new ChiSquaredDistribution(getRandomGenerator(), df, ChiSquaredDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample(); }
public double getZScoreEquivalent(double zscore) { // compute zscore to CDF double cdf = (new NormalDistribution()).cumulativeProbability(zscore); // for normal distribution, mahalanobis distance is chi-squared // https://en.wikipedia.org/wiki/Mahalanobis_distance#Normal_distributions return (new ChiSquaredDistribution(p)).inverseCumulativeProbability(cdf); } }
public RealDistribution getRealDistribution(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); double e1 = getExpressions().get(0).evaluate(context); return new ChiSquaredDistribution(randomGenerator, e1); } };
private static double chi(final double p, final int degreeOfFreedom) { return new ChiSquaredDistribution(degreeOfFreedom) .inverseCumulativeProbability(p); }
public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); double e1 = getExpressions().get(0).evaluate(context); final ChiSquaredDistribution distribution = new ChiSquaredDistribution(randomGenerator, e1); return distribution.sample(); }
@Test public void logProbGraphMatchesKnownLogDensityOfVector() { IntegerVertex k = ConstantVertex.of(1, 1); ChiSquaredVertex vertex = new ChiSquaredVertex(k); LogProbGraph logProbGraph = vertex.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, k, k.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, vertex, DoubleTensor.create(0.25, 0.75)); ChiSquaredDistribution chiSquaredDistribution = new ChiSquaredDistribution(1); double expectedLogDensity = chiSquaredDistribution.logDensity(0.25) + chiSquaredDistribution.logDensity(0.75); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expectedLogDensity); }