@formant/ava
Version:
A framework for automated visual analytics.
24 lines (23 loc) • 914 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buishandUTest = void 0;
var lodash_1 = require("lodash");
var __1 = require("..");
var window_1 = require("./window");
/**
* Buishad U statistics test
*/
function buishandUTest(data) {
var n = data === null || data === void 0 ? void 0 : data.length;
var meanValue = (0, lodash_1.mean)(data);
var Sk = data.map(function (_, index) { return (0, lodash_1.sum)(data.slice(0, index + 1)) - meanValue * (index + 1); });
var U = (0, lodash_1.sumBy)(Sk.slice(0, n - 1), function (item) { return Math.pow(item, 2); }) / (n * (n + 1));
var Smax = (0, __1.maxabs)(Sk);
var maxIndex = Sk.findIndex(function (item) { return item === Smax; });
return {
uValue: U,
index: maxIndex,
significance: 1 - (0, window_1.calcPValue)(data, maxIndex),
};
}
exports.buishandUTest = buishandUTest;