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

106 lines (74 loc) 2.66 kB
## Quick starts ### 1) Use it like `Math` (one-liners) ```js import { Stats } from 'als-statistics'; const X = [10, 12, 13, 9, 14]; const mu = Stats.mean(X); const sd = Stats.stdDevSample(X); const p90 = Stats.p90(X); console.log({ mu, sd, p90 }); // → { mu: 11.6, sd: 1.923..., p90: 13.8 } ``` You can also access many metrics via `Column`: ```js import { Column } from 'als-statistics'; const col = new Column([10, 12, 13, 9, 14], 'Score'); const { mean, stdDev, median, frequencies, flatness } = col; ``` ### 2) Quick analysis: correlation in one line ```js import { Analyze } from 'als-statistics'; const data = { gender: [0, 1, 0, 1, 1, 0], // 0=female, 1=male score: [62, 75, 70, 81, 64, 78], }; const pearson = new Analyze.Correlate(data).pearson('gender', 'score'); const { r, t, df, p } = pearson; console.log({ r, t, df, p }); // r in [-1, 1], two-sided p-value in [0, 1] ``` ### 3) Compare means: Welch t-test (unequal variances) ```js import { Analyze } from 'als-statistics'; const data = { men: [62, 75, 70, 81, 64], women: [78, 73, 69, 71, 74, 77], }; const test = new Analyze.CompareMeans(data).independentWelch('men', 'women'); console.log({ t: test.t, df: test.df, p: test.p }); ``` ### 4) One-way ANOVA (classic & Welch) ```js import { Analyze } from 'als-statistics'; const { CompareMeans } = Analyze; const data = { A: [10, 11, 9, 10], B: [10, 30, -10, 50, -20], C: [12, 13, 12, 11, 14], }; const classic = new CompareMeans(data).anova(); // pooled (equal variances) const welch = new CompareMeans(data).anovaWelch(); // unequal variances console.log({ classic: { F: classic.F, df1: classic.dfBetween, df2: classic.dfWithin, p: classic.p }, welch: { F: welch.F, df1: welch.dfBetween, df2: welch.dfWithin, p: welch.p }, }); ``` ### 5) Table-first workflow (filter → split → analyze) ```js import { Table } from 'als-statistics'; const t = new Table( { gender: [0,1,0,1,1,0], age: [21,22,20,23,19,22], score: [62,75,70,81,64,78] }, { name: 'Survey' } ); // Keep adults 21+ t.filterRowsBy('age', a => a >= 21); // Compare score by gender with Welch // Option A: already split into columns: import { Analyze } from 'als-statistics'; const { CompareMeans } = Analyze; const cm = new CompareMeans({ men: [...], women: [...] }).independentWelch('men', 'women'); // Option B: split first, then pass to CompareMeans: const groups = t.splitBy('gender'); // returns { groupName: number[] } const test = new CompareMeans(groups).independentWelch('0', '1'); ``` ---