UNPKG

@nexys/math-ts

Version:

[![npm version](https://badge.fury.io/js/%40nexys%2Fmath-ts.svg)](https://www.npmjs.com/package/@nexys/math-ts) [![TavisCI](https://travis-ci.com/Nexysweb/tableau-wdc-react.svg?branch=master)](https://travis-ci.com/github/Nexysweb/math-ts) [![Deployment](

44 lines (43 loc) 1.8 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const V = __importStar(require("../vector")); const E = __importStar(require("./estimate")); const M = __importStar(require("../matrix")); const Regresion = __importStar(require("./regression")); exports.Regresion = Regresion; exports.covarianceWMeans = (x, y, mux, muy, n) => { const r = x.map((xi, i) => { const yi = y[i]; return (xi - mux) * (yi - muy); }) .reduce((a, b) => a + b); return r / (n - 1); }; exports.covariance = (x, y) => exports.covarianceWMeans(x, y, V.mean(x), V.mean(y), x.length); exports.covarianceMatrix = (x) => { const t = M.transpose(x); const nCol = t.length; return new Array(nCol).fill(null).map((_, i) => { return new Array(nCol).fill(null).map((_, j) => { return exports.covariance(t[i], t[j]); }); }); }; exports.correlation = (x, y) => exports.covarianceWMeans(x, y, V.mean(x), V.mean(y), x.length) / (E.stddev(x) * E.stddev(y)); exports.autocovarianceWithN = (x, k, n) => { return exports.covariance(x.slice(k), x.slice(0, n - k)); }; exports.autocovariance = (x, k) => exports.autocovarianceWithN(x, k, x.length); const autocorrelationWithC0 = (x, k, c0) => exports.autocovariance(x, k) / c0; exports.autocorrelation = (x, k) => autocorrelationWithC0(x, k, exports.autocovariance(x, 0)); exports.markovProcess = (T, x, n = 1) => { return [0]; }; exports.test = (mu, avg, s, n) => (avg - mu) / (s / Math.sqrt(n));