code: public static double sumOfMeanDifferences(double[] vector, double[] vector2) {
          double mean = sum(vector) / vector.length;
          double mean2 = sum(vector2) / vector2.length;
          double ret = 0;
          for (int i = 0; i < vector.length; i++) {
              double vec1Diff = vector[i] - mean;
              double vec2Diff = vector2[i] - mean2;
              ret += vec1Diff * vec2Diff;
          }
          return ret;
      }
docs: Used for calculating top part of simple regression for
  beta 1
  @param vector the x coordinates
  @param vector2 the y coordinates
  @return the sum of mean differences for the input vectors