(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "rxjs", "rxjs/operators", "./dirtyR", "./mean", "./stdev"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("rxjs"), require("rxjs/operators"), require("./dirtyR"), require("./mean"), require("./stdev"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.rxjs, global.operators, global.dirtyR, global.mean, global.stdev);
    global.dirtyLinearRegression = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _rxjs, _operators, _dirtyR, _mean, _stdev) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;
  _dirtyR = _interopRequireDefault(_dirtyR);
  _mean = _interopRequireDefault(_mean);
  _stdev = _interopRequireDefault(_stdev);

  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

  const dirtyLinearRegression = function dirtyLinearRegression() {
    return source$ => {
      const input$ = source$.pipe((0, _operators.share)());
      const xMean$ = source$.pipe((0, _operators.skip)(1), (0, _operators.map)(instance => instance[0]), (0, _mean.default)());
      const yMean$ = source$.pipe((0, _operators.skip)(1), (0, _operators.map)(instance => instance[instance.length - 1]), (0, _mean.default)());
      const xStdev$ = source$.pipe((0, _operators.map)(instance => instance[0]), (0, _stdev.default)());
      const yStdev$ = source$.pipe((0, _operators.map)(instance => instance[instance.length - 1]), (0, _stdev.default)());
      const r$ = input$.pipe((0, _dirtyR.default)());
      const regression$ = (0, _rxjs.zip)(r$, xMean$, yMean$, xStdev$, yStdev$).pipe((0, _operators.map)(([r, xMean, yMean, xStdev, yStdev]) => {
        const slope = r * (yStdev / xStdev);
        const intercept = yMean - slope * xMean;
        return {
          intercept,
          slope,
          predict: x => slope * x + intercept
        };
      }));
      return regression$;
    };
  };

  var _default = dirtyLinearRegression;
  _exports.default = _default;
});
//# sourceMappingURL=dirtyLinearRegression.js.map