code: public static double xbarVariance(FlatDataCollection flatDataCollection) {
          double n = flatDataCollection.size();
          if(n<=1) {
              throw new IllegalArgumentException("The provided collection must have more than 1 elements.");
          } 
          
          //As explained at http://www.fao.org/docrep/003/x6831e/x6831e12.htm
          //we take the first differences
          Double previousValue = null;
          double xbarVariance = 0.0;
          Iterator<Double> it = flatDataCollection.iteratorDouble();
          while(it.hasNext()) {
              Double yi = it.next();
              if(previousValue!=null) {
                  double delta = yi - previousValue;
                  xbarVariance+=delta*delta;
              }
              previousValue = yi;
          }
          xbarVariance/=(2*n*(n-1));
  
          return xbarVariance;
      }
docs: Calculates Variance for Xbar
  
  @param flatDataCollection
  @return