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
48 lines (41 loc) • 1.38 kB
JavaScript
import test from 'node:test';
import assert from 'node:assert/strict';
import CDF from '../../../lib/analyze/cdf/index.js';
test('CDF.t: значения в [0,1], края', () => {
const xs = [-1e6, -100, -10, -1, 0, 1, 10, 100, 1e6];
for (const x of xs) {
const p = CDF.t(x, 1); // df=1
assert.ok(p >= 0 && p <= 1, `CDF.t(${x}) not in [0,1]: ${p}`);
}
});
test('CDF.f: монотонность по x и диапазон', () => {
const xs = [0.0001, 0.1, 1, 10, 100];
let prev = 0;
for (const x of xs) {
const p = CDF.f(x, 5, 10);
assert.ok(p >= 0 && p <= 1);
assert.ok(p >= prev - 1e-12); // неубывающая
prev = p;
}
});
test('CDF.t: симметрия T-распределения', () => {
const x = 2.5, df = 7;
const p1 = CDF.t(x, df);
const p2 = 1 - CDF.t(-x, df);
assert.ok(Math.abs(p1 - p2) < 1e-12);
});
test('CDF.phi: края и монотонность', () => {
assert.equal(CDF.phi(-Infinity), 0);
assert.equal(CDF.phi( Infinity), 1);
const xs = [-4,-2,0,2,4];
let prev = 0;
for (const x of xs) {
const p = CDF.phi(x);
assert.ok(p >= 0 && p <= 1);
assert.ok(p >= prev - 1e-12);
prev = p;
}
// симметрия: Phi(x) ~= 1 - Phi(-x)
const x = 2.123;
assert.ok(Math.abs(CDF.phi(x) - (1 - CDF.phi(-x))) < 1e-7);
});