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
28 lines (26 loc) • 774 B
JavaScript
import { Pearson } from '../../../lib/analyze/correlate/pearson.js';
import { makeRng } from '../_rng.js';
export const pearsonTool = {
id: 'pearson',
cases: 6,
gen(seed, i) {
const R = makeRng(`${seed}/pr/${i}`);
const n = 30 + (i % 10);
// y = a*x + b + noise
const a = 0.4 + 0.2 * (i % 3), b = 1.5 - 0.5 * (i % 2);
const x = R.normal(0, 1, n);
const noise = R.normal(0, 0.6, n);
const y = x.map((xi, k) => a*xi + b + noise[k]);
return { x, y };
},
compute({x,y}) {
const p = new Pearson({x, y});
return { r: p.r, t: p.t, df: p.df, p: p.p };
},
compare(exp, got, approx) {
approx(got.r, exp.r);
approx(got.t, exp.t);
approx(got.df, exp.df);
approx(got.p, exp.p);
},
};