use of org.apache.commons.math3.stat.inference.WilcoxonSignedRankTest in project GDSC-SMLM by aherbert.
the class CmosAnalysis method computeError.
private void computeError(int slice, ImageStack simulationStack, WindowOrganiser wo) {
final String label = simulationStack.getSliceLabel(slice);
final float[] e = (float[]) simulationStack.getPixels(slice);
final float[] o = (float[]) measuredStack.getPixels(slice);
// Get the mean error
final double[] error = new double[e.length];
for (int i = e.length; i-- > 0; ) {
error[i] = (double) o[i] - e[i];
}
final Statistics s = new Statistics();
s.add(error);
final StringBuilder result = new StringBuilder("Error ").append(label);
result.append(" = ").append(MathUtils.rounded(s.getMean()));
result.append(" +/- ").append(MathUtils.rounded(s.getStandardDeviation()));
// Do statistical tests
final double[] x = SimpleArrayUtils.toDouble(e);
final double[] y = SimpleArrayUtils.toDouble(o);
final PearsonsCorrelation c = new PearsonsCorrelation();
result.append(" : R=").append(MathUtils.rounded(c.correlation(x, y)));
// Plot these
String title = TITLE + " " + label + " Simulation vs Measured";
final Plot plot = new Plot(title, "simulated", "measured");
plot.addPoints(e, o, Plot.DOT);
plot.addLabel(0, 0, result.toString());
ImageJUtils.display(title, plot, wo);
// Histogram the error
new HistogramPlotBuilder(TITLE + " " + label, DoubleData.wrap(error), "Error").setPlotLabel(result.toString()).show(wo);
// Kolmogorov–Smirnov test that the distributions are the same
double pvalue = TestUtils.kolmogorovSmirnovTest(x, y);
result.append(" : Kolmogorov–Smirnov p=").append(MathUtils.rounded(pvalue)).append(' ').append(((pvalue < 0.001) ? REJECT : ACCEPT));
if (slice == 3) {
// Paired T-Test compares two related samples to assess whether their
// population means differ.
// T-Test is valid when the difference between the means is normally
// distributed, e.g. gain
pvalue = TestUtils.pairedTTest(x, y);
result.append(" : Paired T-Test p=").append(MathUtils.rounded(pvalue)).append(' ').append(((pvalue < 0.001) ? REJECT : ACCEPT));
} else {
// Wilcoxon Signed Rank test compares two related samples to assess whether their
// population mean ranks differ
final WilcoxonSignedRankTest wsrTest = new WilcoxonSignedRankTest();
pvalue = wsrTest.wilcoxonSignedRankTest(x, y, false);
result.append(" : Wilcoxon Signed Rank p=").append(MathUtils.rounded(pvalue)).append(' ').append(((pvalue < 0.001) ? REJECT : ACCEPT));
}
ImageJUtils.log(result.toString());
}
Aggregations