private void createBasicStats(Iterable<? extends Comparable<?>> data,Map<String,Double> stats){
  double n=0.0;
  double sum=0.0;
  double sum2=0.0;
  double sum3=0.0;
  double sum4=0.0;
  double mean=0.0;
  double sumOfDiffSquares=0.0;
  double sumOfDiffCubics=0.0;
  double sumOfDiffQuads=0.0;
  for (  Comparable<?> cell : data) {
    if (!(cell instanceof Number)) {
      continue;
    }
    Number numericCell=(Number)cell;
    if (!MathUtils.isCalculatable(numericCell)) {
      continue;
    }
    double val=numericCell.doubleValue();
    if (!stats.containsKey(MIN) || val < stats.get(MIN)) {
      stats.put(MIN,val);
    }
    if (!stats.containsKey(MAX) || val > stats.get(MAX)) {
      stats.put(MAX,val);
    }
    n++;
    double val2=val * val;
    sum+=val;
    sum2+=val2;
    sum3+=val2 * val;
    sum4+=val2 * val2;
    double delta=val - mean;
    double deltaN=delta / n;
    double deltaN2=deltaN * deltaN;
    double term1=delta * deltaN * (n - 1.0);
    mean+=deltaN;
    sumOfDiffQuads+=term1 * deltaN2 * (n * n - 3.0 * n + 3.0) + 6.0 * deltaN2 * sumOfDiffSquares - 4.0 * deltaN * sumOfDiffCubics;
    sumOfDiffCubics+=term1 * deltaN * (n - 2.0) - 3.0 * deltaN * sumOfDiffSquares;
    sumOfDiffSquares+=term1;
  }
  stats.put(N,n);
  stats.put(SUM,sum);
  stats.put(SUM2,sum2);
  stats.put(SUM3,sum3);
  stats.put(SUM4,sum4);
  stats.put(MEAN,mean);
  stats.put(SUM_OF_DIFF_QUADS,sumOfDiffQuads);
  stats.put(SUM_OF_DIFF_CUBICS,sumOfDiffCubics);
  stats.put(SUM_OF_DIFF_SQUARES,sumOfDiffSquares);
  stats.put(VARIANCE,sumOfDiffSquares / (n - 1.0));
  stats.put(POPULATION_VARIANCE,sumOfDiffSquares / n);
  stats.put(SKEWNESS,(sumOfDiffCubics / n) / Math.pow(sumOfDiffSquares / n,3.0 / 2.0) - 3.0);
  stats.put(KURTOSIS,(n * sumOfDiffQuads) / (sumOfDiffSquares * sumOfDiffSquares) - 3.0);
}

private void createBasicStats ( Iterable < ? extends Comparable < ? > > data , Map < String , Double > stats ) { double n = 0.0 ; double sum = 0.0 ; double sum2 = 0.0 ; double sum3 = 0.0 ; double sum4 = 0.0 ; double mean = 0.0 ; double sumOfDiffSquares = 0.0 ; double sumOfDiffCubics = 0.0 ; double sumOfDiffQuads = 0.0 ; for ( Comparable < ? > cell : data ) { if ( ! ( cell instanceof Number ) ) { continue ; } Number numericCell = ( Number ) cell ; if ( ! MathUtils . isCalculatable ( numericCell ) ) { continue ; } double val = numericCell . doubleValue ( ) ; if ( ! stats . containsKey ( MIN ) || val < stats . get ( MIN ) ) { stats . put ( MIN , val ) ; } if ( ! stats . containsKey ( MAX ) || val > stats . get ( MAX ) ) { stats . put ( MAX , val ) ; } n ++ ; double val2 = val * val ; sum += val ; sum2 += val2 ; sum3 += val2 * val ; sum4 += val2 * val2 ; double delta = val - mean ; double deltaN = delta / n ; double deltaN2 = deltaN * deltaN ; double term1 = delta * deltaN * ( n - 1.0 ) ; mean += deltaN ; sumOfDiffQuads += term1 * deltaN2 * ( n * n - 3.0 * n + 3.0 ) + 6.0 * deltaN2 * sumOfDiffSquares - 4.0 * deltaN * sumOfDiffCubics ; sumOfDiffCubics += term1 * deltaN * ( n - 2.0 ) - 3.0 * deltaN * sumOfDiffSquares ; sumOfDiffSquares += term1 ; } stats . put ( N , n ) ; stats . put ( SUM , sum ) ; stats . put ( SUM2 , sum2 ) ; stats . put ( SUM3 , sum3 ) ; stats . put ( SUM4 , sum4 ) ; stats . put ( MEAN , mean ) ; stats . put ( SUM_OF_DIFF_QUADS , sumOfDiffQuads ) ; stats . put ( SUM_OF_DIFF_CUBICS , sumOfDiffCubics ) ; stats . put ( SUM_OF_DIFF_SQUARES , sumOfDiffSquares ) ; stats . put ( VARIANCE , sumOfDiffSquares / ( n - 1.0 ) ) ; stats . put ( POPULATION_VARIANCE , sumOfDiffSquares / n ) ; stats . put ( SKEWNESS , ( sumOfDiffCubics / n ) / Math . pow ( sumOfDiffSquares / n , 3.0 / 2.0 ) - 3.0 ) ; stats . put ( KURTOSIS , ( n * sumOfDiffQuads ) / ( sumOfDiffSquares * sumOfDiffSquares ) - 3.0 ) ; }
utility method that calculates basic statistics like element count , sum , or mean . notes : calculation of higher order statistics is based on formulas from http : / / people . xiph . org / ~ tterribe / notes / homs . html
