List of usage examples for org.apache.commons.math3.stat.inference TestUtils pairedTTest
public static double pairedTTest(final double[] sample1, final double[] sample2) throws NullArgumentException, NoDataException, DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException
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 *//* w w w .jav 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.smlm.ij.plugins.PSFEstimator.java
private void getPairedP(DescriptiveStatistics sample1, DescriptiveStatistics sample2, int i, double[] p, boolean[] identical) throws IllegalArgumentException { if (sample1.getN() < 2) return;/* www . j a v a2 s . c om*/ // 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.pairedTTest(sample1.getValues(), sample2.getValues()); identical[i] = (p[i] > settings.pValue); }
From source file:org.ujmp.commonsmath.PairedTTest.java
public double getDouble(long... coordinates) { try {//from ww w . j a v a 2 s . c o m long var1 = coordinates[ROW]; long var2 = coordinates[COLUMN]; double[] sample1 = new double[(int) getSource().getRowCount()]; double[] sample2 = new double[(int) getSource().getRowCount()]; for (int r = 0; r < getSource().getRowCount(); r++) { sample1[r] = getSource().getAsDouble(r, var1); sample2[r] = getSource().getAsDouble(r, var2); } double pValue = TestUtils.pairedTTest(sample1, sample2); return pValue; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:saffranexperiment.Main.java
/** * @param simulationData A 5D {@link java.util.Arrays Array} with the * following structure:// w w w .java2 s. c om * * <ul> * <li>First dimension: participant types</li> * <li>Second dimension: repeats</li> * <li>Third dimension: experiments</li> * <li>Fourth dimension: participants</li> * <li>Fifth dimension:</li> * <ol type="1"> * <li>Familiar word 1 presentation time</li> * <li>Familiar word 2 presentation time</li> * <li>Novel word 1 presentation time</li> * <li>Novel word 2 presentation time</li> * </ol> * </ul> * * For example, simulationData[7][8][1][17][2] should return the presentation * time for the first novel word achieved by participant 18 in the 9th repeat * of experiment 2 when participant type is set to 8. * * @return A 4D {@link java.util.Arrays Array} with the following structure: * * <ul> * <li>First dimension: participant types</li> * <li>Second dimension: repeats</li> * <li>Third dimension: experiments</li> * <li>Fourth dimension:</li> * <ol type="1"> * <li>Familiar word presentation time mean</li> * <li>Familiar word presentation time standard deviation</li> * <li>Novel word presentation time mean</li> * <li>Novel word presentation time standard deviation</li> * <li>t value for familiar/novel word presentation time means</li> * <li>p value for familiar/novel word presentation time means</li> * </ol> * </ul> * * For example, assigning the result to a variable j and invoking * j[5][3][1][4] would return the t-value associated with the second * experiment of the fourth repeat for participant type 6. */ private static double[][][][] calculateMeanSdTAndPValuesForEachExperimentRepeat( double[][][][][] simulationData) { double[][][][] values = new double[_totalParticipantTypes][_totalRepeats][2][6]; for (int participantType = 0; participantType < _totalParticipantTypes; participantType++) { for (int repeat = 0; repeat < _totalRepeats; repeat++) { for (int experiment = 0; experiment < 2; experiment++) { List<Double> familWordPresentationTimes = new ArrayList(); List<Double> novelWordPresentationTimes = new ArrayList(); for (int participant = 0; participant < _totalParticipants; participant++) { familWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][0]); familWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][1]); novelWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][2]); novelWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][3]); } //Calculate familiar word presentation time mean for experiment. DescriptiveStatistics familWordDescStat = new DescriptiveStatistics(); familWordPresentationTimes.forEach((value) -> familWordDescStat.addValue(value)); values[participantType][repeat][experiment][0] = familWordDescStat.getMean(); values[participantType][repeat][experiment][1] = familWordDescStat.getStandardDeviation(); //Calculate novel word presentation time mean for experiment. DescriptiveStatistics novelWordDescStat = new DescriptiveStatistics(); novelWordPresentationTimes.forEach((value) -> novelWordDescStat.addValue(value)); values[participantType][repeat][experiment][2] = novelWordDescStat.getMean(); values[participantType][repeat][experiment][3] = novelWordDescStat.getStandardDeviation(); //Convert lists containing familiar and novel presentation times to //arrays so we can use the Apache stats library functions for //calculating t and p values. double[] familWordPresentationTimesArr = convertDoubleListToDoubleArray( familWordPresentationTimes); double[] novelWordPresentationTimesArr = convertDoubleListToDoubleArray( novelWordPresentationTimes); //Calculate t value between familiar and novel word presentation times. values[participantType][repeat][0][4] = Math .abs(TestUtils.pairedT(familWordPresentationTimesArr, novelWordPresentationTimesArr)); //Calculate p value between familiar and novel word presentation times. values[participantType][repeat][0][5] = TestUtils.pairedTTest(familWordPresentationTimesArr, novelWordPresentationTimesArr); } } } return values; }