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
27 lines (25 loc) • 779 B
JavaScript
import { CronbachAlpha } from '../../../lib/analyze/correlate/cronbach-alpha.js';
import { makeRng } from '../_rng.js';
export const cronbachTool = {
id: 'cronbach',
cases: 5,
gen(seed, i) {
const R = makeRng(`${seed}/cr/${i}`);
const n = 15 + (i % 4); // респондентов
const k = 4 + (i % 3); // пунктов
const table = {};
for (let j=0; j<k; j++) {
const base = R.normal(50, 10, n);
const noise = R.normal(0, 5 + 2*((j+i)%2), n);
table['Q'+(j+1)] = base.map((x, idx) => x + noise[idx]);
}
return table;
},
compute(table) {
const ca = new CronbachAlpha(table);
return { alpha: ca.alpha };
},
compare(exp, got, approx) {
approx(got.alpha, exp.alpha);
},
};