AggregateSummaryStatistics implements StatisticalSummary,
        Serializable { public static StatisticalSummaryValues aggregate(Collection<SummaryStatistics> statistics) { if (statistics == null) { return null; } Iterator<SummaryStatistics> iterator = statistics.iterator(); if (!iterator.hasNext()) { return null; } SummaryStatistics current = iterator.next(); long n = current.getN(); double min = current.getMin(); double sum = current.getSum(); double max = current.getMax(); double m2 = current.getSecondMoment(); double mean = current.getMean(); while (iterator.hasNext()) { current = iterator.next(); if (current.getMin() < min || Double.isNaN(min)) { min = current.getMin(); } if (current.getMax() > max || Double.isNaN(max)) { max = current.getMax(); } sum += current.getSum(); final double oldN = n; final double curN = current.getN(); n += curN; final double meanDiff = current.getMean() - mean; mean = sum / n; m2 = m2 + current.getSecondMoment() + meanDiff * meanDiff * oldN * curN / n; } final double variance; if (n == 0) { variance = Double.NaN; } else if (n == 1) { variance = 0d; } else { variance = m2 / (n - 1); } return new StatisticalSummaryValues(mean, variance, n, max, min, sum); } AggregateSummaryStatistics();  AggregateSummaryStatistics(SummaryStatistics prototypeStatistics);  AggregateSummaryStatistics(SummaryStatistics prototypeStatistics,
                                      SummaryStatistics initialStatistics); double getMax(); double getMean(); double getMin(); long getN(); double getStandardDeviation(); double getSum(); double getVariance(); double getSumOfLogs(); double getGeometricMean(); double getSumsq(); double getSecondMoment(); StatisticalSummary getSummary(); SummaryStatistics createContributingStatistics(); static StatisticalSummaryValues aggregate(Collection<SummaryStatistics> statistics);  }
@Test public void testAggregate() { double[] totalSample = generateSample(); double[][] subSamples = generatePartition(totalSample); int nSamples = subSamples.length; SummaryStatistics totalStats = new SummaryStatistics(); for (int i = 0; i < totalSample.length; i++) { totalStats.addValue(totalSample[i]); } SummaryStatistics[] subSampleStats = new SummaryStatistics[nSamples]; for (int i = 0; i < nSamples; i++) { subSampleStats[i] = new SummaryStatistics(); } Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>(); for (int i = 0; i < nSamples; i++) { for (int j = 0; j < subSamples[i].length; j++) { subSampleStats[i].addValue(subSamples[i][j]); } aggregate.add(subSampleStats[i]); } StatisticalSummary aggregatedStats = AggregateSummaryStatistics.aggregate(aggregate); assertEquals(totalStats.getSummary(), aggregatedStats, 10E-12); }