code: public static double computeCorrelation(final double[] list1, final double[] list2)
      {
          // R = { N* (Sum(x*y) - Sum(x)*Sum(y)} / sqrt( { N* Sum( x**2 ) - Sum( x )**2} ) * sqrt ( {N
          // * Sum( y**2 ) - Sum( y )**2} )
          double sumXY = 0;
          double sumX = 0;
          double sumY = 0;
          double sumXsquares = 0;
          double sumYsquares = 0;
          final long N = list1.length; // we assume that both list are of equal length
  
          if (list1.length != list2.length) {
              log.fatal("Lists are not the same size (" + list1.length + " - " + list2.length + ").");
              System.exit(1);
          }
  
          for (int i = 0; i < N; i++) {
              final double x = list1[i];
              final double y = list2[i];
              sumXY += x * y;
              sumX += x;
              sumY += y;
              sumXsquares += x * x;
              sumYsquares += y * y;
          }
  
          final double nominator = (N * sumXY - sumX * sumY);
  
          final double root1 = N * sumXsquares - sumX * sumX;
          final double root2 = N * sumYsquares - sumY * sumY;
          final double denominator = Math.sqrt(root1) * Math.sqrt(root2);
  
          final double correlation = nominator / denominator;
  
          return correlation;
      }
docs: Computes the correlation between two datasets.
  @param list1 The first dataset as a double array.
  @param list2 The second dataset as a double array.
  @return The correlation between the two datasets.