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
21 lines (18 loc) • 852 B
JavaScript
import test from 'node:test';
import assert from 'node:assert/strict';
import Regression from '../../lib/analyze/regression/index.js';
test('Regression: interaction term X*Z appears in step 1', () => {
const data = { X:[1,2,3,4,5], Z:[0,1,0,1,0], Y:[2,3,6,7,10] };
const reg = new Regression(data, { yName:'Y', xNames:['X'], type:'linear' });
reg.next(['Z','X*Z']);
const names = reg.steps[1].result.Variable;
assert.ok(names.includes('X*Z'));
});
test('Logistic: predictProba in [0,1] and accuracy present', () => {
const data = { X:[0,1,2,3,4,5,6,7], Y:[0,0,0,0,1,1,1,1] };
const log = new Regression(data, { yName:'Y', xNames:['X'], type:'logistic' });
const s0 = log.steps[0];
const probs = s0.predictProba(s0.X);
assert.ok(probs.every(p => p>=0 && p<=1));
assert.ok(s0.result.Accuracy >= 0 && s0.result.Accuracy <= 1);
});