UNPKG

@formant/ava

Version:

A framework for automated visual analytics.

44 lines (43 loc) 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCorrelationInfo = exports.findCorrelation = void 0; var tslib_1 = require("tslib"); var lodash_1 = require("lodash"); var data_1 = require("../../../data"); var util_1 = require("../util"); var constants_1 = require("../../../data/statistics/constants"); function findCorrelation(x, y, pCorrTestParameter) { var testResult = (0, data_1.pcorrtest)(x, y, pCorrTestParameter); // @ts-ignore Type Result is missing the "pcorr" var rejected = testResult.rejected, pcorr = testResult.pcorr; if (rejected) { return { pcorr: pcorr, significance: Math.abs(pcorr), }; } return null; } exports.findCorrelation = findCorrelation; var getCorrelationInfo = function (props) { var _a, _b; var valid = (0, util_1.preValidation)(props); var insightType = 'correlation'; var data = props.data, measures = props.measures, dimensions = props.dimensions, options = props.options; if ((0, lodash_1.isString)(valid) || !dimensions) return (0, util_1.getNonSignificantInsight)(tslib_1.__assign({ insightType: insightType, infoType: 'verificationFailure' }, ((0, lodash_1.isString)(valid) ? { detailInfo: valid } : {}))); var xField = measures[0].fieldName; var yField = measures[1].fieldName; var x = data.map(function (item) { return item === null || item === void 0 ? void 0 : item[xField]; }); var y = data.map(function (item) { return item === null || item === void 0 ? void 0 : item[yField]; }); var correlationParameter = (_a = options === null || options === void 0 ? void 0 : options.algorithmParameter) === null || _a === void 0 ? void 0 : _a.correlation; var result = findCorrelation(x, y, correlationParameter); if (result) { return [ tslib_1.__assign(tslib_1.__assign({}, result), { type: insightType, measures: [xField, yField], significantInsight: true }), ]; } var info = "The Pearson product-moment correlation test does not pass at the specified significance level ".concat((_b = correlationParameter === null || correlationParameter === void 0 ? void 0 : correlationParameter.alpha) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_PCORRTEST_OPTIONS.alpha, "."); return (0, util_1.getNonSignificantInsight)({ insightType: insightType, infoType: 'noInsight', customInfo: { info: info } }); }; exports.getCorrelationInfo = getCorrelationInfo;