# HG changeset patch # User Sascha L. Teichmann # Date 1335369443 0 # Node ID 4f7d1ea38404a6e2f5ba6d91c078ee6cca9dce41 # Parent 0a84313efe602b27887425721936c8e77183ba09 Added simple Grubb's outlier test. flys-artifacts/trunk@4300 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 0a84313efe60 -r 4f7d1ea38404 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Apr 25 15:15:39 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Apr 25 15:57:23 2012 +0000 @@ -1,8 +1,13 @@ +2012-04-25 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/math/Outlier.java: + New. Simple Grubb's outlier test. Needs testing. ;-) + 2012-04-25 Felix Wolfsteller * src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java (isMinimumX): Implemented minimum finding for x in analogy to the ones for - y values. Stub to label dataset curves in plot. + y values. Stub to label dataset curves in plot. 2012-04-25 Felix Wolfsteller diff -r 0a84313efe60 -r 4f7d1ea38404 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/Outlier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/Outlier.java Wed Apr 25 15:57:23 2012 +0000 @@ -0,0 +1,94 @@ +package de.intevation.flys.artifacts.math; + +import org.apache.commons.math.stat.descriptive.moment.Mean; +import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; + +import org.apache.commons.math.distribution.TDistributionImpl; + +import java.util.List; +import java.util.ArrayList; + +public class Outlier +{ + public static class IndexedValue { + protected int index; + protected double value; + + public IndexedValue() { + } + + public IndexedValue(int index, double value) { + this.index = index; + this.value = value; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } + } // class IndexedValue + + public Outlier() { + } + + public static List findOutliers( + List inputValues, + double alpha + ) { + ArrayList outliers = new ArrayList(); + + ArrayList values = + new ArrayList(inputValues); + + for (;;) { + int N = values.size(); + + if (N < 4) { + break; + } + + Mean mean = new Mean(); + StandardDeviation std = new StandardDeviation(); + + for (IndexedValue value: values) { + mean.increment(value.getValue()); + std.increment(value.getValue()); + } + + double m = mean.getResult(); + double s = std.getResult(); + + double maxZ = -Double.MAX_VALUE; + int iv = -1; + for (int i >= 0; i = N-1; --i) { + IndexedValue v = values.get(i); + double z = Math.abs(m - v.getValue())/s; + if (z > maxZ) { + maxZ = z; + iv = i; + } + } + + double t = Math.sqrt((N*(N-2)*z*z)/((N-1)*(N-1) - N*z*z)) + + TDistributionImpl tdist = new TDistributionImpl(N-2); + + double p = tdist.cumulativeProbability(t) + } + + + return outliers; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :