als-statistics
Version:
A powerful and lightweight JavaScript library for descriptive statistics, regression, clustering, outlier detection, and noise analysis using a flexible table/column architecture.
26 lines (22 loc) • 1.11 kB
JavaScript
const { describe, it } = require('node:test');
const assert = require('node:assert');
const Statistics = require('../index');
describe('table methods', () => {
it('filter', () => {
const stats = new Statistics();
const table = stats.addTable('TestTable');
const col = table.addColumn('values', [1, 2, 3, 4, 5, 100]);
assert.strictEqual(col.mean, (1 + 2 + 3 + 4 + 5 + 100) / 6); // 19.1667
table.filterRows([5]); // Фильтруем последнее значение (100)
assert.strictEqual(col.mean, 3); // (1+2+3+4+5)/5 = 3
});
it('nested descriptive', () => {
const stats = new Statistics();
const table = stats.addTable('TestTable');
table.addColumn('values', [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]);
const descTable = stats.descriptive('confidenceInterval95.high');
assert.strictEqual(descTable.columns['TestTable'].values.length, 1);
const zDescTable = stats.descriptive('zScores.mean');
assert.strictEqual(zDescTable.columns['TestTable'].values.length, 1);
});
});