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

36 lines (30 loc) 1.4 kB
import { describe, it } from 'node:test'; import assert from 'node:assert'; import { Kendall } from '../../../lib/analyze/correlate/kendall.js'; function approx(a,b,eps=1e-10){ assert.ok(Math.abs(a-b)<=eps*(1+Math.max(Math.abs(a),Math.abs(b))),`~${b}, got ${a}`); } describe('Kendall tau-b', () => { it('perfect concordance -> tau=1, p≈0.0833 for n=4', () => { const k = new Kendall({ X:[1,2,3,4], Y:[1,2,3,4] }); approx(k.tau, 1, 1e-12); // допускаем асимптотическое отклонение: 0.05..0.10 assert.ok(k.p > 0.05 && k.p < 0.10, `p=${k.p}`); // если хотите точнее: approx(k.p, 1/12, 0.02); // ±0.02 вокруг 0.08333 }); it('perfect discordance -> tau=-1, p≈0.0833 for n=4', () => { const k = new Kendall({ X:[1,2,3,4], Y:[4,3,2,1] }); approx(k.tau, -1, 1e-12); assert.ok(k.p > 0.05 && k.p < 0.10, `p=${k.p}`); }); it('ties on X and Y: tau=0.5 (двойные тай-пары исключаются)', () => { const k = new Kendall({ X:[1,1,2,3,3], Y:[5,5,4,7,7] }); approx(k.tau, 0.5, 1e-12); }); it('different lengths -> trimmed to min length', () => { const k = new Kendall({ X:[1,2,3,4], Y:[1,2,3] }); // ОЖИДАЕМ 3, после правки конструктора (см. ниже) assert.strictEqual(k.n, 3); }); });