List of usage examples for org.apache.commons.math3.stat.inference TestUtils tTest
public static double tTest(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2) throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException
From source file:Logica.TestTStudent.java
/** * Aplica o Teste t de Estudante sobre os grupos de amostras, * verificando se os genes passaram no critrio de corte * @param p_value valor do criterio de corte * @param analise_amostras//from w ww . j av a 2 s . co m * @return */ @Override public double teste(double p_value, Amostra analise_amostras) { double resultado = TestUtils.tTest(analise_amostras.getAmostras_caso(), analise_amostras.getAmostras_controle()); return resultado; }
From source file:cn.edu.suda.core.stats.StatsUtils.java
public static DataMatrix addTTest(DataMatrix dm, int m, int n) { int col = dm.getDcol(); dm.addCols(2);/* w w w . j a v a 2 s. c o m*/ dm.setColname(col, "ABS_t_value"); dm.setColname(col + 1, "P_value"); for (int i = 0; i < dm.getDrow(); i++) { double[] array = dm.getRow(i); SummaryStatistics stats1 = new SummaryStatistics(); SummaryStatistics stats2 = new SummaryStatistics(); for (int j = 0; j < m; j++) { stats1.addValue(array[j]); } for (int j = m; j < m + n; j++) { stats2.addValue(array[j]); } double var1 = stats1.getVariance(); double var2 = stats2.getVariance(); if (var1 == 0 && var2 == 0) { dm.setValue(i, col, 0); dm.setValue(i, col + 1, 1); } else { double t = Math.abs(TestUtils.t(stats1, stats2)); double p = TestUtils.tTest(stats1, stats2); t = Utils.formatNumber(t, 4); p = Utils.formatNumber(p, 4); dm.setValue(i, col, t); dm.setValue(i, col + 1, p); } } return dm; }
From source file:net.recommenders.rival.evaluation.statistics.StatisticalSignificance.java
/** * Gets the p-value according to the requested method. * * @param method one of "t", "pairedT", "wilcoxon" * @return the p-value according to the requested method *//*from w ww .j av a 2 s . c o m*/ public double getPValue(final String method) { double p = Double.NaN; double[] baselineValues = new double[baselineMetricPerDimension.values().size()]; int i = 0; for (Double d : baselineMetricPerDimension.values()) { baselineValues[i] = d; i++; } double[] testValues = new double[testMetricPerDimension.values().size()]; i = 0; for (Double d : testMetricPerDimension.values()) { testValues[i] = d; i++; } if ("t".equals(method)) { p = TestUtils.tTest(baselineValues, testValues); } else if ("pairedT".equals(method)) { p = TestUtils.pairedTTest(baselineValues, testValues); } else if ("wilcoxon".equals(method)) { p = new WilcoxonSignedRankTest().wilcoxonSignedRankTest(baselineValues, testValues, false); } return p; }
From source file:gdsc.foci.SpotAnalyser.java
private void addResult(int channel, int particle, DescriptiveStatistics[][][] stats) { StringBuilder sb = new StringBuilder(); sb.append(imp.getTitle()).append("\t"); sb.append(channel).append("\t"); sb.append(particle).append("\t"); double sx = stats[channel][INSIDE][particle].getSum(); double sd = stats[channel][INSIDE][particle].getStandardDeviation(); long n = stats[channel][INSIDE][particle].getN(); double av = sx / n; double sx2 = stats[channel][OUTSIDE][particle].getSum(); double sd2 = stats[channel][OUTSIDE][particle].getStandardDeviation(); long n2 = stats[channel][OUTSIDE][particle].getN(); double av2 = sx2 / n2; double p = 0; try {//from ww w . j av a 2s . co m p = TestUtils.tTest(stats[channel][INSIDE][particle], stats[channel][OUTSIDE][particle]); } catch (NumberIsTooSmallException e) { // Ignore } // Correlate inside & outside spot with the principle channel double r = 1; double r2 = 1; if (channel != spotChannel) // Principle channel => No test required { r = new PearsonsCorrelation().correlation(stats[channel][INSIDE][particle].getValues(), stats[spotChannel][INSIDE][particle].getValues()); r2 = new PearsonsCorrelation().correlation(stats[channel][OUTSIDE][particle].getValues(), stats[spotChannel][OUTSIDE][particle].getValues()); } sb.append(IJ.d2s(sx, 0)).append("\t").append(IJ.d2s(av, 2)).append("\t").append(IJ.d2s(sd, 2)).append("\t") .append(IJ.d2s(r, 3)).append("\t"); sb.append(IJ.d2s(sx2, 0)).append("\t").append(IJ.d2s(av2, 2)).append("\t").append(IJ.d2s(sd2, 2)) .append("\t").append(IJ.d2s(r2, 3)).append("\t"); sb.append(IJ.d2s(av / av2, 2)).append("\t"); sb.append(String.format("%.3g", p)); if (java.awt.GraphicsEnvironment.isHeadless()) { IJ.log(sb.toString()); } else { results.append(sb.toString()); } }
From source file:gdsc.smlm.ij.plugins.PSFEstimator.java
private boolean checkAngleSignificance() { boolean tryAgain = false; if (ignore[ANGLE]) return tryAgain; // The angle is relative to the major axis (X). // It could be close to 0, 90 or 180 to allow it to be ignored in favour of a free circular function. final double[] angles = sampleNew[ANGLE].getValues(); for (double testAngle : new double[] { 90, 0, 180 }) { // The angle will be in the 0-180 domain. // We need to compute the Statistical summary around the testAngle. StatisticalSummary sampleStats;//from w w w.ja v a 2 s. c om if (testAngle == 0 || testAngle == 180) { SummaryStatistics stats = new SummaryStatistics(); boolean zeroAngle = (testAngle == 0); for (double a : angles) { if (zeroAngle) { // Convert to -90-90 domain if (a > 90) a -= 180; } else { // Convert to 90-270 domain if (a < 90) a += 180; } stats.addValue(a); } sampleStats = stats; } else { // Already in the 0-180 domain around the angle 90 sampleStats = sampleNew[ANGLE]; } final double p = TestUtils.tTest(testAngle, sampleStats); if (p > settings.pValue) { log("NOTE: Angle is not significant: %g ~ %g (p=%g) => Re-run with fixed zero angle", sampleStats.getMean(), testAngle, p); ignore[ANGLE] = true; config.getFitConfiguration().setFitFunction(FitFunction.FREE_CIRCULAR); tryAgain = true; break; } else debug(" NOTE: Angle is significant: %g !~ %g (p=%g)", sampleNew[ANGLE].getMean(), testAngle, p); } return tryAgain; }
From source file:gdsc.smlm.ij.plugins.PSFEstimator.java
private void getP(StatisticalSummary sample1, StatisticalSummary sample2, int i, double[] p, boolean[] identical) { if (sample1.getN() < 2) return;/*from w w w .j a va2s . co m*/ // The number returned is the smallest significance level at which one can reject the null // hypothesis that the mean of the paired differences is 0 in favor of the two-sided alternative // that the mean paired difference is not equal to 0. For a one-sided test, divide the returned value by 2 p[i] = TestUtils.tTest(sample1, sample2); identical[i] = (p[i] > settings.pValue); }
From source file:org.asoem.greyfish.impl.environment.AgentObjectPoolAT.java
@Test public void testSignificantPerformanceBenefitInSimulationContext() throws Exception { // given//from w w w . j a v a 2 s . c o m final int populationSize = 400; final int steps = 30000; final int runs = 20; final DescriptiveStatistics statisticsWithoutObjectPool = new DescriptiveStatistics(); final DescriptiveStatistics statisticsWithObjectPool = new DescriptiveStatistics(); final ExecutorService executorService = MoreExecutors.sameThreadExecutor(); // when for (int i = 0; i < runs; i++) { // randomize execution order if (RandomGenerators.rng().nextBoolean()) { statisticsWithoutObjectPool.addValue(measureExecutionTime( new SimulationWithoutObjectPoolFactory(populationSize, executorService).newSimulation(), steps)); statisticsWithObjectPool.addValue(measureExecutionTime( new SimulationWithObjectPoolFactory(populationSize, executorService).newSimulation(), steps)); } else { statisticsWithObjectPool.addValue(measureExecutionTime( new SimulationWithObjectPoolFactory(populationSize, executorService).newSimulation(), steps)); statisticsWithoutObjectPool.addValue(measureExecutionTime( new SimulationWithoutObjectPoolFactory(populationSize, executorService).newSimulation(), steps)); } } // then logger.info("Simulation with object pool vs. without object pool: {}, {}", statisticsWithObjectPool, statisticsWithoutObjectPool); assertThat( "The mean elapsed time of the version with an object pool " + "is not less than the mean elapsed time of the version with an object pool", statisticsWithObjectPool.getMean(), is(lessThan(statisticsWithoutObjectPool.getMean()))); // Is it also significantly faster? Make a t-test. // Test assumptions for t-test: normality assertThat("Is not normal distributed", StatisticalTests.shapiroWilk(statisticsWithObjectPool.getValues()).p(), is(lessThan(0.05))); assertThat("Is not normal distributed", StatisticalTests.shapiroWilk(statisticsWithoutObjectPool.getValues()).p(), is(lessThan(0.05))); final double t = TestUtils.t(statisticsWithObjectPool, statisticsWithoutObjectPool); final double p = TestUtils.tTest(statisticsWithObjectPool, statisticsWithoutObjectPool); logger.info("t-test: t={}, p={}", t, p); double qt = new TDistribution(statisticsWithObjectPool.getN() - 1 + statisticsWithoutObjectPool.getN() - 1) .inverseCumulativeProbability(0.975); assertThat("The means are not significantly different", Math.abs(t), is(greaterThan(qt))); }
From source file:org.lpe.common.util.LpeNumericUtils.java
/** * Calculates the p-Value by executing an unpaired t-test for the given to * samples.<br />//from w w w . j ava 2s. c o m * <b>Be aware</b>: The method requires at least two values for each value * list to run a t-test. * * @param values1 * sample one * @param values2 * sample two * @return p-value the t-test p-value in range [0-1]. Can be -1, if at least * one of the lists has below 2 data entries. */ public static double tTest(List<? extends Number> values1, List<? extends Number> values2) { // Apache commons requires at least 2 values to do a t-test if (values1.size() < 2 || values2.size() < 2) { return -1; } double[] sample1 = new double[values1.size()]; double[] sample2 = new double[values2.size()]; int i = 0; for (Number value : values1) { sample1[i] = value.doubleValue(); i++; } i = 0; for (Number value : values2) { sample2[i] = value.doubleValue(); i++; } return TestUtils.tTest(sample1, sample2); }
From source file:org.mskcc.cbio.portal.servlet.ProteinArraySignificanceTestJSON.java
/** * /* ww w .ja v a2 s . c om*/ * @param alterationMap * @param data * @return [unaltered mean, altered mean, p-value, absolute difference] */ private static double[] ttest(double[] unalteredArray, double[] alteredArray) { double alteredMean = StatUtils.mean(alteredArray); double unalteredMean = StatUtils.mean(unalteredArray); double sbsDiff = alteredArray.length == 0 || unalteredArray.length == 0 ? Double.NaN : Math.abs(alteredMean - unalteredMean); if (alteredArray.length < 2 || unalteredArray.length < 2) { return new double[] { unalteredMean, alteredMean, sbsDiff, Double.NaN }; } try { double pvalue = TestUtils.tTest(alteredArray, unalteredArray); return new double[] { unalteredMean, alteredMean, sbsDiff, pvalue }; } catch (Exception e) { return new double[] { unalteredMean, alteredMean, sbsDiff, Double.NaN }; } }