Detect Outlier values in Java Using BoxPlot formula and Apache Commons Math Library

public boolean isOutlier(List<RawItem> rawItems, String value) {

        DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics();
        double dValue = Double.parseDouble(value);

        for (RawItem rawItem : rawItems) {
            double d = Double.parseDouble(rawItem.getValue());

            descriptiveStatistics.addValue(d);
        }

        double Q1 = descriptiveStatistics.getPercentile(25);
        double Q3 = descriptiveStatistics.getPercentile(75);
        double IQR = Q3 - Q1;

        double highRange = Q3 + 3 * IQR;
        double lowRange = Q1 - 3 * IQR;

        if (dValue > highRange || dValue < lowRange) {
            return true;
        }

        return true;
    }

References
https://www.shmoop.com/basic-statistics-probability/box-whisker-plots.html
http://www.baeldung.com/apache-commons-math
https://stackoverflow.com/questions/22888902/get-median-from-number-series-using-apache-commons-math

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.