fitThroughOriginFromMany function

double fitThroughOriginFromMany (Iterable<Tuple2<double, double>> samples)

Least-Squares fitting the points (x,y) to a line y : x -> b*x, returning its best fitting parameter b, where the intercept is zero and b the slope.

Implementation

double fitThroughOriginFromMany(Iterable<Tuple2<double, double>> samples) {
  double mxy = 0.0;
  double mxx = 0.0;

  for (var sample in samples) {
    mxx += sample.item1 * sample.item1;
    mxy += sample.item1 * sample.item2;
  }

  return mxy / mxx;
}