/** * 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)); }
/** * {@inheritDoc} * * @return {@code 2 * k}, where {@code k} is the number of degrees of freedom. */ public double getNumericalVariance() { return 2 * getDegreesOfFreedom(); }
/** * 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); } }
/** * @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; }
public RealDistribution getRealDistribution(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); double e1 = getExpressions().get(0).evaluate(context); return new ChiSquaredDistribution(randomGenerator, e1); } };
/** * * @param df * @param testStatistic * @return */ public static double chiSquareTest(int df, double testStatistic) { ChiSquaredDistribution chi = new ChiSquaredDistribution(df); return chi.density(testStatistic); }
@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); }
public double getPValue(){ double value = cochranMantelHaenszel(); double pvalue = 1.0-chiSquare.cumulativeProbability(value); return pvalue; }
@Override public final void compute() { if (input[0].isDefined() && input[1].isDefined()) { double param = a.getDouble(); double val = b.getDouble(); try { ChiSquaredDistribution dist = getChiSquaredDistribution(param); num.setValue(dist.inverseCumulativeProbability(val)); } catch (Exception e) { num.setUndefined(); } } else { num.setUndefined(); } }
private static double chi(final double p, final int degreeOfFreedom) { return new ChiSquaredDistribution(degreeOfFreedom) .inverseCumulativeProbability(p); }
/** * @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; }
case CHISQUARED: param1 = dof; sampler = new ContinuousSampler(new ChiSquaredDistribution(dof)); break; case EXPONENTIAL:
@Test public void logProbGraphMatchesKnownLogDensityOfScalar() { IntegerVertex k = ConstantVertex.of(1); ChiSquaredVertex vertex = new ChiSquaredVertex(k); LogProbGraph logProbGraph = vertex.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, k, k.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, vertex, DoubleTensor.scalar(0.5)); ChiSquaredDistribution chiSquaredDistribution = new ChiSquaredDistribution(1); double expectedLogDensity = chiSquaredDistribution.logDensity(0.5); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expectedLogDensity); }
.cumulativeProbability(sc.testStat); sc.P = 1 - leftArea;
new ChiSquaredDistribution(null, expected.length - 1.0); return 1.0 - distribution.cumulativeProbability(chiSquare(expected, observed));
/** * @param df The degrees of freedom. * @return Ibid. */ public double nextChiSquare(double df) { return new ChiSquaredDistribution(randomGenerator, df).sample(); }
private void findInliersOutliers(List<? extends IndependentPair<I, D>> data, double[] bestErrors) { inliers.clear(); outliers.clear(); double threshold; if (inlierNoiseLevel > 0) threshold = inlierNoiseLevel * inlierNoiseLevel * new ChiSquaredDistribution(degreesOfFreedom).inverseCumulativeProbability(probability); else { final double sigmahat = 1.4826 * (1 + 5 / (Math.max(1, data.size() - model.numItemsToEstimate()))) * Math.sqrt(bestMedianError); // http://research.microsoft.com/en-us/um/people/zhang/INRIA/Publis/Tutorial-Estim/node25.html threshold = (2.5 * sigmahat) * (2.5 * sigmahat); } for (int i = 0; i < data.size(); i++) { if (bestErrors[i] < threshold) inliers.add(data.get(i)); else outliers.add(data.get(i)); } }
/** * @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; }
return new CauchyDistribution(node.get("median").asDouble(), node.get("scale").asDouble()); case "ChiSquaredDistribution": return new ChiSquaredDistribution(node.get("dof").asDouble()); case "ExponentialDistribution": return new ExponentialDistribution(node.get("mean").asDouble());