UNPKG

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

29 lines (27 loc) 963 B
// Предполагаю интерфейс: new LinearRegression(x,y) => {slope, intercept, r2, t, p} import LinearRegression from '../../../lib/analyze/regression/linear.js'; import { makeRng } from '../_rng.js'; export const regressionTool = { id: 'regression', cases: 6, gen(seed, i) { const R = makeRng(`${seed}/lr/${i}`); const n = 25 + (i % 10); const a = 2.0 + 0.5*(i%3), b = -1.5 + 0.3*(i%2); const x = R.uniform(-2, 3, n); const noise = R.normal(0, 0.8, n); const y = x.map((xi, k) => a*xi + b + noise[k]); return { x, y }; }, compute({x,y}) { const m = new LinearRegression(x, y); return { slope: m.slope, intercept: m.intercept, r2: m.r2, t: m.t, p: m.p }; }, compare(exp, got, approx) { approx(got.slope, exp.slope); approx(got.intercept,exp.intercept); approx(got.r2, exp.r2); approx(got.t, exp.t); approx(got.p, exp.p); }, };