Search in sources :

Example 1 with WilcoxonSignedRankTest

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());
}
Also used : WilcoxonSignedRankTest(org.apache.commons.math3.stat.inference.WilcoxonSignedRankTest) Plot(ij.gui.Plot) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) PearsonsCorrelation(org.apache.commons.math3.stat.correlation.PearsonsCorrelation)

Aggregations

Plot (ij.gui.Plot)1 PearsonsCorrelation (org.apache.commons.math3.stat.correlation.PearsonsCorrelation)1 WilcoxonSignedRankTest (org.apache.commons.math3.stat.inference.WilcoxonSignedRankTest)1 HistogramPlot (uk.ac.sussex.gdsc.core.ij.HistogramPlot)1 HistogramPlotBuilder (uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder)1 Statistics (uk.ac.sussex.gdsc.core.utils.Statistics)1