UNPKG

als-statistics

Version:

Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co

30 lines (26 loc) 1.05 kB
import test from 'node:test'; import assert from 'node:assert/strict'; import { Correlate } from '../../lib/analyze/correlate/index.js'; test('Pearson: sample vs population variants', () => { const data = { X: [1, 2, 3, 4, 5], Y: [2, 4, 6, 8, 10] }; const Rpop = new Correlate(data).pearson('X', 'Y'); const Rsam = new Correlate(data).pearsonSample('X', 'Y'); // оба ~1 assert.ok(Rpop.r > 0.999 && Rsam.r > 0.999); // df = n-2 assert.equal(Rpop.df, 3); }); test('Matrix mode (3+ columns)', () => { const data = { A: [1, 2, 3, 4], B: [2, 3, 4, 5], C: [-1, -2, -3, -4] }; const res = new Correlate(data).pearson(); assert.ok(res['A|B'] && res['A|C'] && res['B|C']); assert.ok(res['A|B'].r > 0.9); assert.ok(res['A|C'].r < -0.9); }); test('Spearman/Kendall two-sided helpers', () => { const data = { X: [1, 2, 3, 4, 5], Y: [5, 4, 3, 2, 1] }; const s2 = new Correlate(data).spearman('X', 'Y'); const k2 = new Correlate(data).kendall('X', 'Y'); assert.ok(s2.p >= 0 && s2.p <= 1); assert.ok(k2.p >= 0 && k2.p <= 1); });