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