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);
}
}
}
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());
}
Aggregations