List of usage examples for org.jfree.data.statistics Statistics calculateMean
public static double calculateMean(Collection values, boolean includeNullAndNaN)
From source file:org.jfree.data.statistics.BoxAndWhiskerCalculator.java
/** * Calculates the statistics required for a {@link BoxAndWhiskerItem} * from a list of <code>Number</code> objects. Any items in the list * that are <code>null</code>, not an instance of <code>Number</code>, or * equivalent to <code>Double.NaN</code>, will be ignored. * * @param values a list of numbers (a <code>null</code> list is not * permitted).// w w w. java 2 s . c o m * @param stripNullAndNaNItems a flag that controls the handling of null * and NaN items. * * @return A box-and-whisker item. * * @since 1.0.3 */ public static BoxAndWhiskerItem calculateBoxAndWhiskerStatistics(List values, boolean stripNullAndNaNItems) { ParamChecks.nullNotPermitted(values, "values"); List vlist; if (stripNullAndNaNItems) { vlist = new ArrayList(values.size()); Iterator iterator = values.listIterator(); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj instanceof Number) { Number n = (Number) obj; double v = n.doubleValue(); if (!Double.isNaN(v)) { vlist.add(n); } } } } else { vlist = values; } Collections.sort(vlist); double mean = Statistics.calculateMean(vlist, false); double median = Statistics.calculateMedian(vlist, false); double q1 = calculateQ1(vlist); double q3 = calculateQ3(vlist); double interQuartileRange = q3 - q1; double upperOutlierThreshold = q3 + (interQuartileRange * 1.5); double lowerOutlierThreshold = q1 - (interQuartileRange * 1.5); double upperFaroutThreshold = q3 + (interQuartileRange * 2.0); double lowerFaroutThreshold = q1 - (interQuartileRange * 2.0); double minRegularValue = Double.POSITIVE_INFINITY; double maxRegularValue = Double.NEGATIVE_INFINITY; double minOutlier = Double.POSITIVE_INFINITY; double maxOutlier = Double.NEGATIVE_INFINITY; List outliers = new ArrayList(); Iterator iterator = vlist.iterator(); while (iterator.hasNext()) { Number number = (Number) iterator.next(); double value = number.doubleValue(); if (value > upperOutlierThreshold) { outliers.add(number); if (value > maxOutlier && value <= upperFaroutThreshold) { maxOutlier = value; } } else if (value < lowerOutlierThreshold) { outliers.add(number); if (value < minOutlier && value >= lowerFaroutThreshold) { minOutlier = value; } } else { minRegularValue = Math.min(minRegularValue, value); maxRegularValue = Math.max(maxRegularValue, value); } minOutlier = Math.min(minOutlier, minRegularValue); maxOutlier = Math.max(maxOutlier, maxRegularValue); } return new BoxAndWhiskerItem(new Double(mean), new Double(median), new Double(q1), new Double(q3), new Double(minRegularValue), new Double(maxRegularValue), new Double(minOutlier), new Double(maxOutlier), outliers); }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat_Raw.java
/** * /*from w w w. j a va 2s .c om*/ * @param isDemo data come from demo(true) or dataTable(false) * @return */ protected CategoryDataset createDataset(boolean isDemo) { double mean, stdDev; if (isDemo) { SERIES_COUNT = 3; CATEGORY_COUNT = 5; VALUE_COUNT = 10; values_storage = new String[SERIES_COUNT][CATEGORY_COUNT]; DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset(); for (int s = 0; s < SERIES_COUNT; s++) { for (int c = 0; c < CATEGORY_COUNT; c++) { Double[] values = createValueList(0, 20.0, VALUE_COUNT); values_storage[s][c] = vs; mean = Statistics.calculateMean(values, false); stdDev = Statistics.getStdDev(values); dataset.add(mean, stdDev, "Series " + s, "Category " + c); } } domainLabel = "Series"; rangeLabel = "Value"; return dataset; } else { // setXYArray(); setArrayFromTable(); String[][] x = new String[xyLength][independentVarLength]; String[][] y = new String[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) for (int i = 0; i < xyLength; i++) x[i][index] = indepValues[i][index]; for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) y[i][index] = depValues[i][index]; SERIES_COUNT = xyLength; CATEGORY_COUNT = independentVarLength; DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset(); values_storage = new String[SERIES_COUNT][CATEGORY_COUNT]; for (int s = 0; s < SERIES_COUNT; s++) { for (int c = 0; c < CATEGORY_COUNT; c++) { if (x[s][c] != null && x[s][c].length() != 0) { Double[] values = createValueList(x[s][c]); values_storage[s][c] = x[s][c]; mean = Statistics.calculateMean(values, false); stdDev = Statistics.getStdDev(values); if (y[s][0] != null) dataset.add(mean, stdDev, y[s][0], independentHeaders[c]); } } } return dataset; } }