code: public static double lag1(double[] vals) {
          double mean = mean(vals);
          int size = vals.length;
          double r1;
          double q = 0;
          double v = (vals[0] - mean) * (vals[0] - mean);
          for (int i = 1; i < size; i++) {
              double delta0 = (vals[i - 1] - mean);
              double delta1 = (vals[i] - mean);
              q += (delta0 * delta1 - q) / (i + 1);
              v += (delta1 * delta1 - v) / (i + 1);
          }
          r1 = q / v;
          return r1;
      }
docs: Returns the lag-1 autocorrelation of a dataset;