List of usage examples for org.jfree.data.statistics BoxAndWhiskerItem BoxAndWhiskerItem
public BoxAndWhiskerItem(double mean, double median, double q1, double q3, double minRegularValue, double maxRegularValue, double minOutlier, double maxOutlier, List outliers)
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerXYDatasetTest.java
/** * Some checks for the add() method.//from w ww .j a va 2 s . co m */ @Test public void testAdd() { DefaultBoxAndWhiskerXYDataset dataset = new DefaultBoxAndWhiskerXYDataset("S1"); BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()); dataset.add(new Date(33L), item1); assertEquals(1.0, dataset.getY(0, 0).doubleValue(), EPSILON); assertEquals(1.0, dataset.getMeanValue(0, 0).doubleValue(), EPSILON); assertEquals(2.0, dataset.getMedianValue(0, 0).doubleValue(), EPSILON); assertEquals(3.0, dataset.getQ1Value(0, 0).doubleValue(), EPSILON); assertEquals(4.0, dataset.getQ3Value(0, 0).doubleValue(), EPSILON); assertEquals(5.0, dataset.getMinRegularValue(0, 0).doubleValue(), EPSILON); assertEquals(6.0, dataset.getMaxRegularValue(0, 0).doubleValue(), EPSILON); assertEquals(7.0, dataset.getMinOutlier(0, 0).doubleValue(), EPSILON); assertEquals(8.0, dataset.getMaxOutlier(0, 0).doubleValue(), EPSILON); assertEquals(new Range(5.0, 6.0), dataset.getRangeBounds(false)); }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
private static final BoxAndWhiskerItem convertDistanceAnalyserToBoxAndWhiskerItem(final DistanceAnalyser da) { if (da.count() == 0) return null; // final BoxAndWhiskerItem result = // new BoxAndWhiskerItem(da.getMean(), da.getMedian(), da // .getFirstQuartile(), da.getThirdQuartile(), da.getMin(), da // .getMax(), da.getMin(), da.getMax(), new ArrayList()); // final BoxAndWhiskerItem result = // new BoxAndWhiskerItem(da.getMean(), da.getMedian(), da // .getFirstQuartile(), da.getThirdQuartile(), // da.getMinRegularValue(), da.getMaxRegularValue(), da // .getMinOutlier(), da.getMaxOutlier(), da.getOutliers()); final BoxAndWhiskerItem result = new BoxAndWhiskerItem(da.getMean(), da.getMedian(), da.getFirstQuartile(), da.getThirdQuartile(), da.getMinRegularValue(), da.getMaxRegularValue(), da.getMin(), da.getMax(), new ArrayList()); return result; }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java
/** * A simple test for bug report 1701822. *//*from www . j ava 2 s . co m*/ @Test public void test1701822() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); try { dataset.add( new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(5.0), new Double(6.0), null, new Double(8.0), new ArrayList()), "ROW1", "COLUMN1"); dataset.add( new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(5.0), new Double(6.0), new Double(7.0), null, new ArrayList()), "ROW1", "COLUMN2"); } catch (NullPointerException e) { assertTrue(false); } }
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)./*from w ww. j a v a 2s . c om*/ * @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:org.jfree.data.statistics.DefaultBoxAndWhiskerXYDatasetTest.java
/** * Some checks for the getRangeBounds() method. *///from w ww . java2s . c o m @Test public void testGetRangeBounds() { DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset("S"); d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(true)); d1.add(new Date(1L), new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList())); assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(true)); d1.add(new Date(2L), new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList())); assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(true)); }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java
/** * Some checks for the add() method./*www . j a va 2 s . co m*/ */ @Test public void testAdd() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()); dataset.add(item1, "R1", "C1"); assertEquals(2.0, dataset.getValue("R1", "C1").doubleValue(), EPSILON); assertEquals(1.0, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON); assertEquals(2.0, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON); assertEquals(3.0, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON); assertEquals(4.0, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON); assertEquals(5.0, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(6.0, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(7.0, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(8.0, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(new Range(7.0, 8.0), dataset.getRangeBounds(false)); }
From source file:de.hs.mannheim.modUro.reader.BoxAndWhiskersPlotDiagram.java
/** * Creates dataset for BoxWhiskerPlot./*from w w w . j a va 2s . c o m*/ * * @return */ private BoxAndWhiskerCategoryDataset createDataset() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); List<String> sortedModels = bwpModel.getModelTypeName(); sortedModels.sort(String::compareTo); for (String model : sortedModels) { StatisticValues stat = bwpModel.getStatisticValues().get(model); BoxAndWhiskerItem item = new BoxAndWhiskerItem(stat.getMean(), stat.getSecondPercentile(), stat.getFirstPercentile(), stat.getLastPercentile(), stat.getMin(), stat.getMax(), stat.getMin(), stat.getMax(), new ArrayList<>()); // Second parameter is the row key (?), using always the same works: int n = stat.size(); dataset.add(item, "", model + " (n=" + n + ")"); } return dataset; }
From source file:gui.TraitViewerDialog.java
@SuppressWarnings("rawtypes") private ChartPanel getChart(int selectedRow) { ArrayList<Float> data = new ArrayList<Float>(); for (float[] row : tFile.getRows()) { if (row[selectedRow + 1] != (float) -99.0) { data.add(row[selectedRow + 1]); }/*from w w w . ja va 2 s . c om*/ } BoxAndWhiskerItem a = BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(data); java.util.List l = new ArrayList(0); a = new BoxAndWhiskerItem(a.getMean(), a.getMedian(), a.getQ1(), a.getQ3(), a.getMinRegularValue(), a.getMaxRegularValue(), a.getMinRegularValue(), a.getMaxRegularValue(), l); traitstats.setText(showBoxAndWhiskerItem(a)); DefaultBoxAndWhiskerCategoryDataset ds2 = new DefaultBoxAndWhiskerCategoryDataset(); ds2.add(a, (Comparable) 1, (Comparable) 1); JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, null, ds2, false); chart.removeLegend(); // XYPlot plot = chart.getXYPlot(); CategoryPlot plot = chart.getCategoryPlot(); plot.getDomainAxis().setVisible(false); BoxAndWhiskerRenderer b = (BoxAndWhiskerRenderer) plot.getRenderer(); // b.setFillBox(false); b.setSeriesPaint(0, new Color(236, 55, 169)); b.setSeriesOutlinePaint(1, new Color(131, 79, 112)); b.setBaseOutlineStroke(new BasicStroke(1.0f)); // b.get b.setWhiskerWidth(0.8); b.setBaseOutlinePaint(new Color(84, 144, 201)); b.setDefaultEntityRadius(2); b.setMaximumBarWidth(0.18); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPopupMenu(null); return chartPanel; }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java
/** * Some checks for the add() method./* w w w.j a v a 2 s . co m*/ */ @Test public void testAddUpdatesCachedRange() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()); dataset.add(item1, "R1", "C1"); // now overwrite this item with another BoxAndWhiskerItem item2 = new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList()); dataset.add(item2, "R1", "C1"); assertEquals(2.5, dataset.getValue("R1", "C1").doubleValue(), EPSILON); assertEquals(1.5, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON); assertEquals(2.5, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON); assertEquals(3.5, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON); assertEquals(4.5, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON); assertEquals(5.5, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(6.5, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(7.5, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(8.5, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(new Range(7.5, 8.5), dataset.getRangeBounds(false)); }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java
/** * Some checks for the getRangeBounds() method. *///from w w w.jav a 2 s. c om @Test public void testGetRangeBounds() { DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset(); d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "R1", "C1"); assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(false)); assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(true)); d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList()), "R1", "C1"); assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(false)); assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(true)); d1.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList()), "R2", "C1"); assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(false)); assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(true)); // this replaces the entry with the current minimum value, but the new // minimum value is now in a different item d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 8.6, 9.6, new ArrayList()), "R1", "C1"); assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(false)); assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(true)); }