/** * 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)); }
return 1.0 - distribution.cumulativeProbability(chiSquare(expected, observed));
return 1.0 - distribution.cumulativeProbability(g(expected, observed));
return 1 - distribution.cumulativeProbability( gDataSetsComparison(observed1, observed2));
return 1 - distribution.cumulativeProbability( chiSquareDataSetsComparison(observed1, observed2));
return 1 - distribution.cumulativeProbability(chiSquare(counts));
/** * @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; }
public double getPValue(){ double value = cochranMantelHaenszel(); double pvalue = 1.0-chiSquare.cumulativeProbability(value); return pvalue; }
private double norm(double z) { double q = z * z; double piOver2 = Math.PI / 2.0; if (Math.abs(q) > 7.0) { return (1.0 - 1.0 / q + 3.0 / (q * q)) * Math.exp(-q / 2.0) / (Math.abs(z) * Math.sqrt(piOver2)); } else { return new ChiSquaredDistribution(1).cumulativeProbability(q); } }
private void computeChiSquare(){ df = nrow*ncol-nrow-ncol; if(df<=0.0){ probChiSquare = 0.0; }else{ ChiSquaredDistribution cs = new ChiSquaredDistribution(df); double sum = 0.0; for(int i=0;i<nrow;i++){ for(int j=0;j<ncol;j++){ sum += Math.log((data[i][j]+1e-6)/N)*data[i][j]; } } chiSquare = 2.0*(fmin+sum); probChiSquare = 1.0-cs.cumulativeProbability(chiSquare); } }
public static double getChiSquareCutoff(double alpha, int df) { double low = 0.0; double high = 50.0; double mid = 25.0; ChiSquaredDistribution dist = new ChiSquaredDistribution(df); while (high - low > 1e-4) { mid = (high + low) / 2.0; double _alpha = 2.0 * (1.0 - dist.cumulativeProbability(Math.abs(mid))); if (_alpha > alpha) { low = mid; } else { high = mid; } } return mid; }
/** * @param observed means non-negative vector * @param expected means positive vector * @return p value */ public static double chiSquareTest(@Nonnull final double[] observed, @Nonnull final double[] expected) { final ChiSquaredDistribution distribution = new ChiSquaredDistribution(expected.length - 1.d); return 1.d - distribution.cumulativeProbability(chiSquare(observed, expected)); }
public String toString() { NumberFormat nf = new DecimalFormat("0.0000"); String report = ""; report = report + (ny0 + " cases have " + target + " = 0; " + ny1 + " cases have " + target + " = 1.\n"); report = report + ("Overall Model Fit...\n"); report = report + (" Chi Square = " + nf.format(chiSq) + "; df = " + numRegressors + "; " + "p = " + nf.format(new ChiSquaredDistribution(numRegressors).cumulativeProbability(chiSq)) + "\n"); report = report + ("\nCoefficients and Standard Errors...\n"); report = report + ("\tCoeff.\tStdErr\tprob.\tsig."); report += "\n"; for (int i = 0; i < regressorNames.size(); i++) { report += "\n" + regressorNames.get(i) + "\t" + nf.format(coefs[i + 1]) + "\t" + nf.format(stdErrs[i + 1]) + "\t" + nf.format(probs[i + 1]) + "\t" + (probs[i + 1] < alpha ? "*" : ""); } report = report + ("\n\nIntercept = " + nf.format(intercept) + "\n"); return report; } }
/** * This method offers effective calculation for multiple entries rather than calculation * individually * * @param observeds means non-negative matrix * @param expecteds means positive matrix * @return (chi2 value[], p value[]) */ public static Map.Entry<double[], double[]> chiSquare(@Nonnull final double[][] observeds, @Nonnull final double[][] expecteds) { Preconditions.checkArgument(observeds.length == expecteds.length); final int len = expecteds.length; final int lenOfEach = expecteds[0].length; final ChiSquaredDistribution distribution = new ChiSquaredDistribution(lenOfEach - 1.d); final double[] chi2s = new double[len]; final double[] ps = new double[len]; for (int i = 0; i < len; i++) { chi2s[i] = chiSquare(observeds[i], expecteds[i]); ps[i] = 1.d - distribution.cumulativeProbability(chi2s[i]); } return new AbstractMap.SimpleEntry<double[], double[]>(chi2s, ps); } }
/** * Complementary CDF for Chi^2 distribution * */ @Test public void test_04() { Gpr.debug("Test"); Random rand = new Random(20130609); // Create many random tests for (int i = 0; i < 100000; i++) { // Random degrees of freedom int degOfFreedom = rand.nextInt(20) + 1; // Random chi^2 double chi2 = 0; for (int j = 0; j < degOfFreedom; j++) { double z = rand.nextGaussian(); chi2 += z * z; } // Calculate complementary probabilities double pval = ScoreList.chiSquareCDFComplementary(chi2, degOfFreedom); double prob = new ChiSquaredDistribution(degOfFreedom).cumulativeProbability(chi2); // Assert that statistics add to 1.0 Assert.assertEquals(1.0, pval + prob); } }
/** * 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)); }
/** * @return the p-value for the model. */ public double getPValue() { double chiSquare = getChiSquare(); int dof = semPm.getDof(); if (dof <= 0) { return Double.NaN; } else if (chiSquare < 0) { return Double.NaN; } else { return 1.0 - new ChiSquaredDistribution(dof).cumulativeProbability(chiSquare); } }
/** * 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)); }
/** * Takes a list of tetrads for the given data set and returns the chi square value for the test. We assume that the * tetrads are non-redundant; if not, a matrix exception will be thrown. * <p> * Calculates the T statistic (Bollen and Ting, p. 161). This is significant if tests as significant using the Chi * Square distribution with degrees of freedom equal to the number of nonredundant tetrads tested. */ public double getPValue(IntSextad... sextads) { // int df = sextads.length; int df = dofHarman(sextads.length); double chisq = calcChiSquare(sextads); // double cdf = ProbUtils.chisqCdf(chisq, df); double cdf = new ChiSquaredDistribution(df).cumulativeProbability(chisq); return 1.0 - cdf; }