List of usage examples for org.apache.commons.math3.stat.inference TestUtils chiSquareTest
public static boolean chiSquareTest(final long[][] counts, final double alpha) throws NullArgumentException, DimensionMismatchException, NotPositiveException, OutOfRangeException, MaxCountExceededException
From source file:com.github.rinde.rinsim.util.StochasticSuppliersTest.java
boolean chiSquare(List<? extends Number> expectations, List<? extends Number> observations, double confidence) { final double chi = TestUtils.chiSquareTest(Doubles.toArray(expectations), Longs.toArray(observations)); return !(chi < confidence); }
From source file:com.github.rinde.rinsim.scenario.generator.PoissonProcessTest.java
/** * Checks whether the observations conform to a Poisson process with the * specified intensity. Uses a chi square test with the specified confidence. * The null hypothesis is that the observations are the result of a poisson * process./*from ww w .j a v a 2 s.c o m*/ * @param observations * @param intensity * @param confidence * @return <code>true</code> if the observations */ static boolean isPoissonProcess(Frequency observations, double intensity, double length, double confidence) { final PoissonDistribution pd = new PoissonDistribution(length * intensity); final Iterator<?> it = observations.valuesIterator(); final long[] observed = new long[observations.getUniqueCount()]; final double[] expected = new double[observations.getUniqueCount()]; int index = 0; while (it.hasNext()) { final Long l = (Long) it.next(); observed[index] = observations.getCount(l); expected[index] = pd.probability(l.intValue()) * observations.getSumFreq(); if (expected[index] == 0) { return false; } index++; } final double chi = TestUtils.chiSquareTest(expected, observed); return !(chi < confidence); }
From source file:blast.specification.cutoff.TUITCutoffSet.java
/** * Checks whether the given {@link NormalizedHit}s E-value ratio is higher than the cutoff value * * @param oneNormalizedHit {@link NormalizedHit} (assuming the hit with a worse (higher) e-value) * @param anotherNormalizedHit {@link NormalizedHit} (assuming the hit with a better (lower) e-value) * @return {@code true} Performs a Chi Squared test on a contingency table <br> * <table class="tg-table-plain"> * <tr>/*from www . java 2s . c om*/ * <th></th> * <th>Better hit</th> * <th>Other hit</th> * <th>Sum</th> * </tr> * <tr class="tg-even"> * <td>Corrected Match</td> * <td>Number of identities</td> * <td>Number of identities</td> * <td></td> * </tr> * <tr> * <td>Corrected Mismatch</td> * <td>Align.length-(Total Gaps - Gapopen)</td> * <td>Align.length-(Total Gaps - Gapopen)</td> * <td></td> * </tr> * <tr class="tg-even"> * <td>Sum</td> * <td></td> * <td></td> * <td></td> * </tr> * <caption>TUIT cont. table</caption> * </table> * , returns true if the test has shown the statistical significant prevalence of one alignment over another * , {@code false} otherwise or if either of the pointers * point to {@code null} */ public boolean hitsAreStatisticallyDifferent(final NormalizedHit oneNormalizedHit, final NormalizedHit anotherNormalizedHit) { int oneAlignLen = 0; for (Hsp hsp : oneNormalizedHit.getHit().getHitHsps().getHsp()) { oneAlignLen += Integer.valueOf(hsp.getHspAlignLen()); } int anotherAlignLen = 0; for (Hsp hsp : anotherNormalizedHit.getHit().getHitHsps().getHsp()) { anotherAlignLen += Integer.valueOf(hsp.getHspAlignLen()); } int oneNumIdents = 0; for (Hsp hsp : oneNormalizedHit.getHit().getHitHsps().getHsp()) { oneNumIdents += Integer.valueOf(hsp.getHspIdentity()); } int anotherNumIdents = 0; for (Hsp hsp : anotherNormalizedHit.getHit().getHitHsps().getHsp()) { anotherNumIdents += Integer.valueOf(hsp.getHspIdentity()); } int oneNumGaps = 0; for (Hsp hsp : oneNormalizedHit.getHit().getHitHsps().getHsp()) { oneNumGaps += Integer.valueOf(hsp.getHspGaps()); } int anotherNumGaps = 0; for (Hsp hsp : anotherNormalizedHit.getHit().getHitHsps().getHsp()) { anotherNumGaps += Integer.valueOf(hsp.getHspGaps()); } int oneNumGapOpens = 0; for (Hsp hsp : oneNormalizedHit.getHit().getHitHsps().getHsp()) { oneNumGapOpens += calculateNumberOfGapOpens(hsp.getHspQseq()) + calculateNumberOfGapOpens(hsp.getHspHseq()); } int anotherNumGapOpens = 0; for (Hsp hsp : anotherNormalizedHit.getHit().getHitHsps().getHsp()) { anotherNumGapOpens += calculateNumberOfGapOpens(hsp.getHspQseq()) + calculateNumberOfGapOpens(hsp.getHspHseq()); } return TestUtils.chiSquareTest( new long[][] { { oneNumIdents, anotherNumIdents }, { (oneAlignLen - (oneNumGaps - oneNumGapOpens)) - oneNumIdents, (anotherAlignLen - (anotherNumGaps - anotherNumGapOpens)) - anotherNumIdents } }, this.alpha); }