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
31 lines (27 loc) • 1.18 kB
JavaScript
import test from 'node:test';
import assert from 'node:assert/strict';
import { IndependentTTest } from '../../lib/analyze/compare-means/independent-t-test.js';
import { PairedTTest } from '../../lib/analyze/compare-means/paired.js';
import { OneSampleTTest } from '../../lib/analyze/compare-means/one-sample.js';
test('Paired trims to min length and computes diffs A-B', () => {
const a = [1, 2, 3, 4, 5];
const b = [1, 1, 2, 3]; // shorter
const t = new PairedTTest({ A: a, B: b });
assert(t.n >= 2);
// meanDelta should be > 0 because A-B mostly positive
assert.ok(typeof t.meanDelta === 'number');
});
test('Independent: Student == Welch on equal variances (approx)', () => {
const g1 = [1, 2, 3, 4, 5, 6];
const g2 = [2, 3, 4, 5, 6, 7];
const stud = new IndependentTTest({ g1, g2 }, false);
const wel = new IndependentTTest({ g1, g2 }, true);
// df differ in general, но t близки
assert.ok(Math.abs(stud.t - wel.t) < 1e-6);
});
test('One-sample: shifting mu0 flips t sign', () => {
const x = [2, 3, 4, 5, 6];
const t1 = new OneSampleTTest({ X: x }, 0);
const t2 = new OneSampleTTest({ X: x }, 10);
assert.ok(t1.t > 0 && t2.t < 0);
});