code: public static double calculateCorrelation(TransposeDataList transposeDataList) { //unsafe internalData pointer. modifying the variable internalData
          Object[] keys = transposeDataList.keySet().toArray();
          if(keys.length!=2) {
              throw new IllegalArgumentException("The collection must contain observations from 2 groups.");
          }
          
          Object keyX = keys[0];
          Object keyY = keys[1];
          
          FlatDataList flatDataListX = transposeDataList.get(keyX);
          FlatDataList flatDataListY = transposeDataList.get(keyY);
  
          int n = flatDataListX.size();
          if(n<=0 || n!=flatDataListY.size()) {
              throw new IllegalArgumentException("The number of observations in each group must be equal and larger than 0.");
          }
  
          //The following loops calculate twice the scores. That the check both if A>B and B<A and count it twice
          int numberOfConcordant=0;
          int numberOfDisconcordant=0;
          
          
          for(int i=0;i<n;++i) {
              for(int j=0;j<n;++j) {
                  double xi = flatDataListX.getDouble(i);
                  double xj = flatDataListX.getDouble(j);
                  double yi = flatDataListY.getDouble(i);
                  double yj = flatDataListY.getDouble(j);
                  
                  double sign=(xi-xj)*(yi-yj); //if this has a positive sign then they are concordant
                  if(sign>0) {
                      ++numberOfConcordant;
                  }
                  else if(sign<0) {
                      ++numberOfDisconcordant;
                  }
              }
          }
          /*
          foreach(transposeDataList[0] as i=>&xi) {
              foreach(transposeDataList[0] as j=>&xj) {
              }
          }
          */
          numberOfConcordant/=2; //divide by 2 because we counted them twice
          numberOfDisconcordant/=2; //divide by 2 because we counted them twice
  
          double R=(numberOfConcordant-numberOfDisconcordant)/(n*(n-1.0)/2.0);
  
          return R;
      }
docs: Calculates Kendall Tau's Correlation for a given transposed array (2xn table)
  
  @param transposeDataList
  @return