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
17 lines (14 loc) • 635 B
JavaScript
import { describe, it } from 'node:test';
import assert from 'node:assert';
import Stats from '../../lib/descriptive/index.js';
function approx(a,b,eps=1e-12){ assert.ok(Math.abs(a-b)<=eps*(1+Math.max(Math.abs(a),Math.abs(b))),`~${b}, got ${a}`); }
describe('Descriptive.zScore', () => {
it('uses mean, not stdDev twice', () => {
const values = [0, 1, 2, 3, 4]; // mean=2, std≈1.5811
const stdDev = Stats.stdDev({ values });
const mean = Stats.mean({ values });
const z = Stats.zScore({ stdDev, mean, values }, 4);
// (4-2)/std ≈ 1.264911064
approx(z, (4-mean)/stdDev, 1e-12);
});
});