jstat, mathjs, and simple-statistics are JavaScript libraries that provide mathematical and statistical functionality for browser and Node.js environments. jstat focuses on statistical distributions, matrix operations, and basic linear algebra with a MATLAB-like API. mathjs is a comprehensive mathematics library supporting symbolic computation, units, complex numbers, matrices, and expression parsing. simple-statistics offers a minimal, functional approach to descriptive statistics and inference with no dependencies and an emphasis on clarity and correctness.
When you need to do math or statistics in the browser — whether for data dashboards, scientific tools, or analytics features — picking the right library matters. jstat, mathjs, and simple-statistics each solve overlapping problems but with very different philosophies. Let’s compare them head-to-head on real-world tasks.
jstat is a statistics-focused library inspired by MATLAB and R. It excels at probability distributions, hypothesis tests, and vector/matrix operations. Think of it as a toolbox for inferential statistics.
mathjs is a general-purpose mathematics engine. It handles everything from basic arithmetic to symbolic algebra, units, matrices, and expression evaluation. It’s more like a programmable calculator with superpowers.
simple-statistics provides clean, functional implementations of common statistical methods — mean, median, regression, confidence intervals — with an emphasis on correctness and simplicity. No frills, no side effects.
All three can compute basic descriptive stats, but their APIs differ significantly.
jstat operates on arrays using static methods:
import jStat from 'jstat';
const data = [1, 2, 3, 4, 5];
const mean = jStat.mean(data); // 3
const median = jStat.median(data); // 3
mathjs uses a unified math.* namespace and supports both arrays and its own matrix type:
import { mean, median } from 'mathjs';
const data = [1, 2, 3, 4, 5];
const meanVal = mean(data); // 3
const medianVal = median(data); // 3
simple-statistics exports pure functions that take arrays and return values:
import { mean, median } from 'simple-statistics';
const data = [1, 2, 3, 4, 5];
const avg = mean(data); // 3
const med = median(data); // 3
💡 Note:
simple-statisticsandmathjsallow direct imports of only what you use, aiding tree-shaking.jstattypically imports the entire module.
This is where jstat shines. It includes PDF, CDF, inverse CDF, and random sampling for many distributions.
jstat example — find the 95th percentile of a standard normal distribution:
import jStat from 'jstat';
const z95 = jStat.normal.inv(0.95, 0, 1); // ≈ 1.64485
mathjs has limited built-in distribution support. You’d need to implement PDFs manually or use external formulas:
// mathjs does not include statistical distributions out of the box
// You'd have to write or import helpers
simple-statistics includes only a few distributions (normal, t) via helper functions:
import { epsilon } from 'simple-statistics';
// No direct .inv() method; uses approximation functions
// For example, to get z-score for 95%:
function ppf(p) {
// Implementation required — not provided directly
}
✅ Verdict: For serious work with statistical distributions (e.g., p-values, critical values),
jstatis the only one of the three with full coverage.
Need to multiply matrices or solve linear systems? Here’s how they compare.
jstat treats arrays as vectors/matrices and offers linear algebra methods:
import jStat from 'jstat';
const A = [[1, 2], [3, 4]];
const B = [[5], [6]];
const product = jStat.multiply(A, B); // [[17], [39]]
mathjs has first-class matrix support with rich operations:
import { matrix, multiply } from 'mathjs';
const A = matrix([[1, 2], [3, 4]]);
const B = matrix([[5], [6]]);
const result = multiply(A, B); // matrix([[17], [39]])
simple-statistics does not support matrix operations at all. It’s purely scalar and array-based.
// simple-statistics: no matrix functionality
✅ Verdict: For linear algebra, choose
jstatfor lightweight needs ormathjsfor more advanced features (decompositions, eigenvalues, etc.).
Running a t-test on two samples?
jstat includes common tests:
import jStat from 'jstat';
const sample1 = [1, 2, 3];
const sample2 = [2, 3, 4];
const tStat = jStat.studentttest(sample1, sample2).tstat;
mathjs does not include statistical tests. You’d need to implement them yourself.
// mathjs: no built-in t-test
simple-statistics provides a clean t-test implementation:
import { tTest } from 'simple-statistics';
const result = tTest([1, 2, 3], [2, 3, 4]);
// Returns { pValue: ..., testStatistic: ... }
Similarly, for confidence intervals:
// simple-statistics
import { confidenceInterval } from 'simple-statistics';
const ci = confidenceInterval([1,2,3,4,5], 0.95);
// jstat
const ci2 = jStat.confidence([1,2,3,4,5], 0.95);
// mathjs: not available
✅ Verdict: Both
jstatandsimple-statisticssupport inference;simple-statisticsoffers clearer return structures, whilejstatcovers more test types.
What if users enter "2 * sin(x) + 5" and you need to evaluate it?
Only mathjs supports this out of the box:
import { evaluate, parse } from 'mathjs';
const expr = parse('2 * sin(x) + 5');
const result = expr.evaluate({ x: Math.PI / 2 }); // 7
// Or simpler:
evaluate('2 * sin(pi / 2) + 5'); // 7
jstat and simple-statistics have no expression parsing capability.
✅ Verdict: If your app needs formula input from users,
mathjsis the only viable choice here.
Converting meters to feet or adding time durations?
Only mathjs handles units:
import { unit } from 'mathjs';
const length = unit('5 m');
const inFeet = length.to('ft'); // ≈ 16.4 ft
The other two libraries treat numbers as dimensionless scalars.
While we won’t cite exact numbers, consider these architectural traits:
simple-statistics: Exports individual functions. You only bundle what you import. Ideal for performance-sensitive apps.mathjs: Highly modular but large overall. Supports custom builds to reduce size, but default imports can be heavy.jstat: Typically imported as a single object. Harder to tree-shake; you often pull in the whole library even if you only use mean().simple-statistics is purely functional — no side effects, no mutation.
jstat sometimes mutates inputs (e.g., in-place sorting for quantiles), which can surprise developers.
mathjs generally avoids mutation but uses object-oriented wrappers (like Matrix) that encapsulate state.
As of 2024:
jstat is actively maintained (latest release in 2023), with no deprecation notices.mathjs is under active development with regular releases and strong community support.simple-statistics is stable and maintained, with updates as recently as 2023. No deprecation warnings.None of these packages are deprecated. All are safe for new projects.
Despite differences, all three share important qualities:
All run in modern browsers and server environments without polyfills.
Each provides or supports TypeScript definitions (via @types/ or built-in).
Given the same input, they produce consistent results — crucial for testing and reproducibility.
Safe for commercial use.
| Feature | jstat | mathjs | simple-statistics |
|---|---|---|---|
| Descriptive Stats | ✅ | ✅ | ✅ |
| Probability Distributions | ✅ (full suite) | ❌ | ⚠️ (limited) |
| Hypothesis Tests | ✅ (t-test, ANOVA, etc.) | ❌ | ✅ (basic tests) |
| Matrix Operations | ✅ (basic) | ✅ (advanced) | ❌ |
| Expression Parsing | ❌ | ✅ | ❌ |
| Units & Dimensions | ❌ | ✅ | ❌ |
| Functional / Immutable | ⚠️ (sometimes mutates) | ✅ (mostly) | ✅ (pure functions) |
| Tree-Shaking Friendly | ❌ | ✅ (with care) | ✅ |
simple-statistics. It’s small, clear, and covers 90% of common needs.jstat for its distribution and test coverage.mathjs for its unmatched breadth.Don’t over-engineer: if you only need mean() and median(), simple-statistics is likely the best fit. But if you’re computing p-values from F-distributions or solving linear systems, reach for jstat. And if your users type math into text boxes, mathjs is your only real option.
Choose based on the mathematical scope of your problem — not just today’s feature, but what you might need next month.
Choose jstat if you need robust support for probability distributions (e.g., t, chi-square, F), hypothesis testing, or matrix operations in a compact package. It’s well-suited for scientific or analytical frontend applications where you’re performing inferential statistics or working with vectors and matrices directly. However, its API can feel dated, and it lacks broader mathematical features like expression parsing or unit handling.
Choose mathjs when your application requires a full-featured math engine — including symbolic expressions, unit conversions, complex numbers, arbitrary precision, or matrix algebra beyond basic stats. It’s ideal for calculators, engineering tools, or educational apps where users input formulas or need dimensional analysis. Be aware that its flexibility comes with greater bundle size and API complexity compared to focused alternatives.
Choose simple-statistics for lightweight, readable implementations of common descriptive and inferential statistics (mean, median, quantiles, t-tests, etc.) with zero dependencies. It’s perfect for data visualization dashboards, analytics UIs, or any scenario where you prioritize code clarity, testability, and minimal footprint over advanced math capabilities. Avoid it if you need matrix operations, distributions beyond basics, or symbolic computation.
jStat provides native javascript implementations of statistical functions. Full details are available in the docs. jStat provides more functions than most libraries, including the weibull, cauchy, poisson, hypergeometric, and beta distributions. For most distributions, jStat provides the pdf, cdf, inverse, mean, mode, variance, and a sample function, allowing for more complex calculations.
NOTICE: The previous case sensitive jStat module will no longer be
updated. Instead use the all lowercase jstat when doing an npm install or
similar.
jStat can be used in the browser. The jStat object will be added to the
window. For example:
<script src="components/jstat.js"></script> <!-- include jStat, from the CDN or otherwise -->
<script>
...
var jstat = this.jStat(dataset); // jStat will be added to the window
...
data[i]['cum'] = jstat.normal(jstat.mean(), jstat.stdev()).cdf(data[i].x);
...
</script>
The library is hosted on jsDelivr using the following url:
//cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js
Note that 'latest' can be replaced with any released verion of jStat.
Currently jStat is exposed as j$ and jStat inside an object, rather than
exported directly. This may confuse some module loaders, however should be
easily remedied with the correct configuration.
To install via npm:
npm install --save jstat
When loading under Node be sure to reference the child object.
var { jStat } = require('jstat').
For RequireJS not only exports but also init function must be specified.
requirejs.config({
paths: {
'jstat': 'path/to/jstat/dist/jstat.min'
},
shim: {
jstat: {
exports: ['j$', 'jStat'],
init: function () {
return {
j$: j$,
jStat: jStat
};
}
}
}
});
In order to build jStat, you need to have GNU make 3.8 or later, Node.js 0.2 or later, and git 1.7 or later. (Earlier versions might work OK, but are not tested.)
Windows users have two options:
Mac OS users should install Xcode (comes on your Mac OS install DVD, or downloadable from
Apple's Xcode site) and
http://mxcl.github.com/homebrew/. Once Homebrew is installed, run brew install git to install git,
and brew install node to install Node.js.
Linux/BSD users should use their appropriate package managers to install make, git, and node, or build from source if you swing that way.
First, clone a copy of the jStat git repo by running git clone git://github.com/jstat/jstat.git.
To download all necessary libraries run npm install.
Then, to get a complete, minified version of jStat and all documentation,
simply cd to the jstat directory and type make. If you don't have Node
installed and/or want to make a basic, uncompressed, unlinted version of jstat,
use make jstat instead of make.
The built version of jStat will be put in the dist/ subdirectory.
Generate just the documentation by running make doc. Documentation will be
placed in dist/docs by default.
To remove all built files, run make clean.
Execute all tests by running make test.
Or if you wish to run a specific test, cd to test/<subdir> and run node <some_test>-test.js.
Both the minified and unminified source are located in the dist/ directory.
For those who don't want to build it themselves.
jStat is now going to follow most of the v8 JavaScript guidelines. There will be plenty of source that uses the old style, but we're going to work away from that.
Also, we'll be going through and reimplementing a good portion of the code to run faster. Hopefully it won't take too long to get the project on one basic standard.
When submitting pull requests, no need to check in dist/*.js. They'll be
recompiled for distribution anyway.
We always like discussion of how to improve jStat. Join us at our mailing list and let us know what you'd like to see. Also come ask questions in the #jstat channel on irc.freenode.net.