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
20 lines (16 loc) • 767 B
JavaScript
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { PairedTTest } from '../../../lib/analyze/compare-means/paired.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('PairedTTest', () => {
it('basic paired t', () => {
const A=[1,2,3,4], B=[1,2,2,4]; // diffs: [0,0,1,0]; mean=0.25; sd=0.5; se=0.25 => t=1, df=3
const tt = new PairedTTest({ A, B });
assert.strictEqual(tt.df, 3);
approx(tt.t, 1.0, 1e-12);
assert.ok(tt.p > 0.35 && tt.p < 0.45, `p=${tt.p}`);
});
it('not throws on unequal lengths (sameSize=true)', () => {
assert.doesNotThrow(() => new PairedTTest({ A:[1,2,3], B:[1,2] }));
});
});