statistics
Inferential statistics capability pack (pure JavaScript, zero dependencies): descriptive summary (mean, median, mode, variance, standard deviation, min, max, range, quartiles, IQR, skewness...
statistics (engines/adapters/domain/statistics)
Inferential-statistics capability pack. Pure JavaScript, zero dependencies — every special function (erf / normal CDF, log-gamma, regularized incomplete beta & gamma for t / F / chi-square p-values, Acklam inverse-normal) is implemented inline with Node built-ins only.
One contract (export default { metadata, adapters }); every tool takes ONE args object (an HTTP POST body maps 1:1) and returns a plain JSON-serializable result. Numeric inputs are coerced from JSON arrays, CSV/space strings, or single numbers; bad inputs throw TypeError/Error.
Tools (17)
| tool | what it does |
|---|---|
describe | full descriptive summary: mean, median, mode, min/max/range, Q1/Q3/IQR, sample & population variance/stdDev, skewness, excess kurtosis |
correlation | Pearson (linear) or Spearman (rank) correlation of x,y + t-test significance (method) |
covariance | sample (n-1) and population (n) covariance of x,y |
linearRegression | ordinary least squares y = slope·x + intercept, R², std errors, slope t-test |
polynomialRegression | least-squares polynomial fit of any degree (normal equations + Gaussian elimination), R² + adjusted R² |
tTest | Student t-test: one-sample (vs mu), two-sample (Welch), or paired (method) |
zTest | one-sample z-test with known population sigma |
chiSquareTest | chi-square goodness-of-fit (observed/expected) or independence (2D contingency observed) |
anovaOneWay | one-way ANOVA / F-test across groups (array of numeric arrays) |
confidenceInterval | CI for a mean — t-interval (sigma unknown) or z-interval (sigma given), any confidence |
normalPdf / normalCdf | normal density / cumulative probability at value for mean,sigma |
binomial | binomial PMF P(X=k) or CDF (cumulative) for n,p |
poisson | Poisson PMF P(X=k) or CDF (cumulative) for rate lambda |
zScore | standardize one value (vs mean/sigma) or a whole data sample |
percentile | value(s) at given percentile(s) via linear interpolation |
histogram | equal-width bins (Sturges' rule default, or explicit bins) with counts + density |
Usage
import statistics from './index.js';
statistics.adapters.describe({ data: [4, 8, 15, 16, 23, 42] });
// { count: 6, mean: 18, median: 15.5, ... skewness, kurtosis }
statistics.adapters.tTest({ method: 'two-sample', x: [5, 7, 6, 8], y: [9, 11, 10, 12] });
// { variant: 'welch', t: ..., df: ..., pValue: ... }
statistics.adapters.linearRegression({ x: [1, 2, 3, 4], y: [2, 4, 6, 8] });
// { slope: 2, intercept: 0, rSquared: 1, equation: 'y = 2x + 0' }
statistics.adapters.binomial({ n: 10, p: 0.5, k: 3, cumulative: true });
op selects the tool when invoked through the adapter registry / MCP gateway. adapterToServer() (@leumas/mcp-kit) exposes each tool as an MCP tool + HTTP endpoint + form.
DRY boundary vs numbers
numbers owns descriptive series analytics (running average, normalize/scale, percentile insights, anomaly detection, derivatives, weighted scoring) plus scalar math and unit/base conversion. This pack owns inferential statistics: hypothesis tests, regression modelling, correlation/covariance, probability distributions, confidence intervals, and standardization/percentile/histogram utilities. describe is offered here as a fuller descriptive summary (skew/kurtosis/quartiles) so a statistical workflow is self-contained — for lightweight, streaming series work reach for numbers instead. Neither pack imports the other.