UNPKG

@visactor/vmind

Version:

<div align="center"> <a href="https://github.com/VisActor#gh-light-mode-only" target="_blank"> <img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/> </a> <a href="https://githu

39 lines (35 loc) 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.ScatterPlotCorrelation = void 0; const vutils_1 = require("@visactor/vutils"), statistics_1 = require("../statistics"), type_1 = require("../../type"), types_1 = require("../../../../types"), pearsonAlgo = (context, options) => { const {seriesDataMap: seriesDataMap, cell: cell, insights: insights} = context, {threshold: pearsonThreshold = .8, withoutSeries: withoutSeries = !1} = options || {}, {y: celly, x: cellx, color: color} = cell, yField = (0, vutils_1.isArray)(celly) ? celly[0] : celly, xField = (0, vutils_1.isArray)(cellx) ? cellx[0] : cellx, seriesField = (0, vutils_1.isArray)(color) ? color[0] : color, result = [], seriesNames = Object.keys(seriesDataMap); return withoutSeries && seriesNames.length > 1 ? [] : (seriesNames.forEach((series => { let seriesDataset = seriesDataMap[series].map((d => d.dataItem)); const outlierData = insights.filter((insight => insight.type === type_1.InsightType.Outlier && (!seriesField || String(insight.data[0][seriesField]) === series))).map((i => i.data[0])); outlierData.length > 0 && (seriesDataset = seriesDataset.filter((dataItem => !outlierData.find((od => od[xField] === dataItem[xField] && od[yField] === dataItem[yField] && (!seriesField || dataItem[seriesField] === od[seriesField])))))); const xMeasureSet = seriesDataset.map((d => d[yField])), yMeasureSet = seriesDataset.map((d => d[xField])); if (xMeasureSet.length !== yMeasureSet.length) return; const pearsonCoefficient = (0, statistics_1.pearsonCorrelationCoeff)(xMeasureSet, yMeasureSet), degree = yMeasureSet.length - 2, tValue = pearsonCoefficient * Math.sqrt(degree) / Math.sqrt(1 - pearsonCoefficient ** 2), threshold = (0, statistics_1.studentTQuantile)(.975, degree); Math.abs(pearsonCoefficient) > pearsonThreshold && Math.abs(tValue) >= threshold && result.push({ type: type_1.InsightType.Correlation, fieldId: [ xField, yField ], significant: Math.abs(pearsonCoefficient), seriesName: series, info: { isLinearCorrelation: !0 } }); })), result); }; exports.ScatterPlotCorrelation = { name: "pearson-coefficient", chartType: [ types_1.ChartType.ScatterPlot ], forceChartType: [ types_1.ChartType.ScatterPlot ], insightType: type_1.InsightType.Correlation, algorithmFunction: pearsonAlgo }; //# sourceMappingURL=pearson.js.map