Docs
/
engines/adapters/domain/statistics

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)

toolwhat it does
describefull descriptive summary: mean, median, mode, min/max/range, Q1/Q3/IQR, sample & population variance/stdDev, skewness, excess kurtosis
correlationPearson (linear) or Spearman (rank) correlation of x,y + t-test significance (method)
covariancesample (n-1) and population (n) covariance of x,y
linearRegressionordinary least squares y = slope·x + intercept, R², std errors, slope t-test
polynomialRegressionleast-squares polynomial fit of any degree (normal equations + Gaussian elimination), R² + adjusted R²
tTestStudent t-test: one-sample (vs mu), two-sample (Welch), or paired (method)
zTestone-sample z-test with known population sigma
chiSquareTestchi-square goodness-of-fit (observed/expected) or independence (2D contingency observed)
anovaOneWayone-way ANOVA / F-test across groups (array of numeric arrays)
confidenceIntervalCI for a mean — t-interval (sigma unknown) or z-interval (sigma given), any confidence
normalPdf / normalCdfnormal density / cumulative probability at value for mean,sigma
binomialbinomial PMF P(X=k) or CDF (cumulative) for n,p
poissonPoisson PMF P(X=k) or CDF (cumulative) for rate lambda
zScorestandardize one value (vs mean/sigma) or a whole data sample
percentilevalue(s) at given percentile(s) via linear interpolation
histogramequal-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.

Source shared/engines/adapters/domain/statistics/README.md (no-git)markdownjson
Generated from the Leumas repository. Every page cites the file it came from.leumas.techllms.txt