code: public static double covariance(TransposeDataList transposeDataList, boolean isSample) {
          if(transposeDataList.size()!=2) {
              throw new IllegalArgumentException("The collection must contain observations from 2 groups.");
          }
          
          double covariance = 0.0;
          
          Object[] keys = transposeDataList.keySet().toArray();
          Object keyX = keys[0];
          Object keyY = keys[1];
          
          FlatDataCollection flatDataCollectionX = transposeDataList.get(keyX).toFlatDataCollection();
          FlatDataCollection flatDataCollectionY = transposeDataList.get(keyY).toFlatDataCollection();
          
          int n = flatDataCollectionX.size();
          if(n<=1 || n!=flatDataCollectionY.size()) {
              throw new IllegalArgumentException("The number of observations in each group must be equal and larger than 1.");
          }
          
          double meanX = mean(flatDataCollectionX);
          double meanY = mean(flatDataCollectionY);
          
          Iterator<Double> iteratorX = flatDataCollectionX.iteratorDouble();
          Iterator<Double> iteratorY = flatDataCollectionY.iteratorDouble();
          while (iteratorX.hasNext() && iteratorY.hasNext()) {
              covariance+=(iteratorX.next()-meanX)*
                          (iteratorY.next()-meanY);
          }
          
          if(isSample) {
              covariance/=(n-1.0);
          }
          else {
              covariance/=n;
          }
          
          return covariance;
      }
docs: Calculates the covariance for a given transposed array (2xn table)
  @param transposeDataList
  @param isSample
  @return