Search in sources :

Example 1 with PearsonsCorrelation

use of org.apache.commons.math3.stat.correlation.PearsonsCorrelation 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)

Example 2 with PearsonsCorrelation

use of org.apache.commons.math3.stat.correlation.PearsonsCorrelation in project lucene-solr by apache.

the class CorrelationEvaluator method evaluate.

public Number evaluate(Tuple tuple) throws IOException {
    StreamEvaluator colEval1 = subEvaluators.get(0);
    StreamEvaluator colEval2 = subEvaluators.get(1);
    List<Number> numbers1 = (List<Number>) colEval1.evaluate(tuple);
    List<Number> numbers2 = (List<Number>) colEval2.evaluate(tuple);
    double[] column1 = new double[numbers1.size()];
    double[] column2 = new double[numbers2.size()];
    for (int i = 0; i < numbers1.size(); i++) {
        column1[i] = numbers1.get(i).doubleValue();
    }
    for (int i = 0; i < numbers2.size(); i++) {
        column2[i] = numbers2.get(i).doubleValue();
    }
    PearsonsCorrelation pearsonsCorrelation = new PearsonsCorrelation();
    return pearsonsCorrelation.correlation(column1, column2);
}
Also used : List(java.util.List) PearsonsCorrelation(org.apache.commons.math3.stat.correlation.PearsonsCorrelation)

Example 3 with PearsonsCorrelation

use of org.apache.commons.math3.stat.correlation.PearsonsCorrelation in project presto by prestodb.

the class TestDoubleCorrelationAggregation method testNonTrivialAggregation.

private void testNonTrivialAggregation(double[] y, double[] x) {
    PearsonsCorrelation corr = new PearsonsCorrelation();
    double expected = corr.correlation(x, y);
    checkArgument(Double.isFinite(expected) && expected != 0.0 && expected != 1.0, "Expected result is trivial");
    testAggregation(expected, createDoublesBlock(box(y)), createDoublesBlock(box(x)));
}
Also used : PearsonsCorrelation(org.apache.commons.math3.stat.correlation.PearsonsCorrelation)

Example 4 with PearsonsCorrelation

use of org.apache.commons.math3.stat.correlation.PearsonsCorrelation 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

PearsonsCorrelation (org.apache.commons.math3.stat.correlation.PearsonsCorrelation)4 Statistics (gdsc.core.utils.Statistics)1 Plot (ij.gui.Plot)1 List (java.util.List)1 MannWhitneyUTest (org.apache.commons.math3.stat.inference.MannWhitneyUTest)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