corCoefficient property

num corCoefficient

Calculates the correlation coefficient. This is the strength of the linear relationship of given points.

(Also known as r) The larger abs(r) is, the stronger the correlation.

Implementation

num get corCoefficient {
  var Sx = x.stdDev;
  var Sy = y.stdDev;
  num r = 0;
  var avgX = x.mean;
  var avgY = y.mean;
  for (var n = 0; n < x.length; n++) {
    r += ((x[n] - avgX) * (y[n] - avgY));
  }
  r /= ((Sx * Sy)*(x.length-1));
  return r;
}