Search in sources :

Example 1 with MannWhitneyUTest

use of org.apache.commons.math3.stat.inference.MannWhitneyUTest in project EnrichmentMapApp by BaderLab.

the class MannWhitneyRankSumTest method testMannWhitneyPvalue.

@Test
public void testMannWhitneyPvalue() throws Exception {
    String testDataFileName = "src/test/resources/org/baderlab/csplugins/enrichmentmap/MannWhitneyTest_pvalues.csv";
    InputStream reader = new StreamUtil().getInputStream(testDataFileName);
    try (Scanner scanner = new Scanner(reader, "UTF-8")) {
        String fullText = scanner.useDelimiter("\\A").next();
        String[] lines = fullText.split("\n");
        String[] tokens, x_s, y_s;
        int i, j, k;
        for (i = 1; i < lines.length; i++) {
            // Split
            tokens = lines[i].split(",");
            // Parse x contents
            x_s = tokens[0].split("\\s");
            x = new double[x_s.length];
            for (j = 0; j < x_s.length; j++) x[j] = Double.parseDouble(x_s[j]);
            // Parse y contents
            y_s = tokens[1].split("\\s");
            y = new double[y_s.length];
            for (k = 0; k < y_s.length; k++) y[k] = Double.parseDouble(y_s[k]);
            // Procure expected pval
            expected_pVal = Double.parseDouble(tokens[2]);
            MannWhitneyUTest test = new MannWhitneyUTest(NaNStrategy.FAILED, TiesStrategy.AVERAGE);
            pValue = test.mannWhitneyUTest(x, y);
            assertEquals(expected_pVal, pValue, 0.0);
        }
    }
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) MannWhitneyUTest(org.apache.commons.math3.stat.inference.MannWhitneyUTest) MannWhitneyUTest(org.apache.commons.math3.stat.inference.MannWhitneyUTest) Test(org.junit.Test)

Example 2 with MannWhitneyUTest

use of org.apache.commons.math3.stat.inference.MannWhitneyUTest in project GDSC-SMLM by aherbert.

the class CMOSAnalysis method computeError.

private void computeError(int slice, ImageStack simulationStack) {
    String label = simulationStack.getSliceLabel(slice);
    float[] e = (float[]) simulationStack.getPixels(slice);
    float[] o = (float[]) measuredStack.getPixels(slice);
    // Get the mean error
    Statistics s = new Statistics();
    for (int i = e.length; i-- > 0; ) s.add(o[i] - e[i]);
    StringBuilder result = new StringBuilder("Error ").append(label);
    result.append(" = ").append(Utils.rounded(s.getMean()));
    result.append(" +/- ").append(Utils.rounded(s.getStandardDeviation()));
    // Do statistical tests
    double[] x = Utils.toDouble(e), y = Utils.toDouble(o);
    PearsonsCorrelation c = new PearsonsCorrelation();
    result.append(" : R=").append(Utils.rounded(c.correlation(x, y)));
    // Mann-Whitney U is valid for any distribution, e.g. variance
    MannWhitneyUTest test = new MannWhitneyUTest();
    double p = test.mannWhitneyUTest(x, y);
    result.append(" : Mann-Whitney U p=").append(Utils.rounded(p)).append(' ').append(((p < 0.05) ? "reject" : "accept"));
    if (slice != 2) {
        // T-Test is valid for approximately Normal distributions, e.g. offset and gain
        p = TestUtils.tTest(x, y);
        result.append(" : T-Test p=").append(Utils.rounded(p)).append(' ').append(((p < 0.05) ? "reject" : "accept"));
        p = TestUtils.pairedTTest(x, y);
        result.append(" : Paired T-Test p=").append(Utils.rounded(p)).append(' ').append(((p < 0.05) ? "reject" : "accept"));
    }
    Utils.log(result.toString());
}
Also used : MannWhitneyUTest(org.apache.commons.math3.stat.inference.MannWhitneyUTest) Statistics(gdsc.core.utils.Statistics) PearsonsCorrelation(org.apache.commons.math3.stat.correlation.PearsonsCorrelation)

Aggregations

MannWhitneyUTest (org.apache.commons.math3.stat.inference.MannWhitneyUTest)2 Statistics (gdsc.core.utils.Statistics)1 InputStream (java.io.InputStream)1 Scanner (java.util.Scanner)1 PearsonsCorrelation (org.apache.commons.math3.stat.correlation.PearsonsCorrelation)1 Test (org.junit.Test)1