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

31 lines (29 loc) 975 B
import { OneWayAnova } from '../../../lib/analyze/compare-means/one-way-anova.js'; import { makeRng } from '../_rng.js'; export const anovaTool = { id: 'anova', cases: 6, gen(seed, i) { const R = makeRng(`${seed}/aov/${i}`); const k = 3 + (i % 2); const groups = {}; for (let g=0; g<k; g++) { groups['G'+(g+1)] = R.normal(g*0.3, 1 + 0.5*((g+i)%2), 10 + (i%3)); } return groups; }, compute(groups) { const aov = new OneWayAnova(groups, false); return { F: aov.F, dfBetween: aov.dfBetween, dfWithin: aov.dfWithin, p: aov.p, msw: aov.msw, }; }, compare(exp, got, approx) { approx(got.F, exp.F); if (got.dfBetween !== exp.dfBetween) throw new Error(`dfBetween ${got.dfBetween} != ${exp.dfBetween}`); if (got.dfWithin !== exp.dfWithin) throw new Error(`dfWithin ${got.dfWithin} != ${exp.dfWithin}`); approx(got.p, exp.p); approx(got.msw, exp.msw); }, };