jstat vs mathjs vs simple-statistics
Statistical and Mathematical Computation Libraries for JavaScript
jstatmathjssimple-statisticsSimilar Packages:

Statistical and Mathematical Computation Libraries for JavaScript

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.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
jstat01,803706 kB62--
mathjs015,0349.43 MB181a month agoApache-2.0
simple-statistics03,5061.18 MB232 months agoISC

Statistical and Mathematical Libraries Compared: jstat vs mathjs vs simple-statistics

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.

📊 Core Focus: What Each Library Is Built For

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.

🔢 Basic Statistics: Mean, Median, and Quantiles

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-statistics and mathjs allow direct imports of only what you use, aiding tree-shaking. jstat typically imports the entire module.

📈 Probability Distributions: Working with Normal, T, and Chi-Square

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), jstat is the only one of the three with full coverage.

🧮 Matrix Operations: Linear Algebra in Practice

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 jstat for lightweight needs or mathjs for more advanced features (decompositions, eigenvalues, etc.).

🧪 Hypothesis Testing: T-Tests and Confidence Intervals

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 jstat and simple-statistics support inference; simple-statistics offers clearer return structures, while jstat covers more test types.

🧾 Expression Parsing and Dynamic Formulas

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, mathjs is the only viable choice here.

📏 Units and Physical Quantities

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.

📦 Bundle Size and Tree-Shaking Friendliness

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().

🔄 Mutability and Functional Style

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.

🛑 Maintenance and Deprecation Status

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.

🤝 Shared Strengths

Despite differences, all three share important qualities:

1. Browser and Node.js Support

All run in modern browsers and server environments without polyfills.

2. TypeScript Compatibility

Each provides or supports TypeScript definitions (via @types/ or built-in).

3. Deterministic Output

Given the same input, they produce consistent results — crucial for testing and reproducibility.

4. MIT or Similar Permissive Licenses

Safe for commercial use.

📊 Summary Table

Featurejstatmathjssimple-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)

💡 Final Guidance

  • Building a data dashboard or analytics UI? → Start with simple-statistics. It’s small, clear, and covers 90% of common needs.
  • Developing a scientific tool, A/B test analyzer, or stats-heavy app? → Use jstat for its distribution and test coverage.
  • Creating a calculator, engineering simulator, or app with user-defined formulas? → Go with 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.

How to Choose: jstat vs mathjs vs simple-statistics

  • jstat:

    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.

  • mathjs:

    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.

  • simple-statistics:

    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.

README for jstat

jStat - JavaScript Statistical Library

npm version

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.

Using jStat in a Browser

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>

CDN jsDelivr Hits

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.

Module Loaders

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.

NodeJS & NPM

To install via npm:

npm install --save jstat

When loading under Node be sure to reference the child object.

var { jStat } = require('jstat').

RequireJS Shim

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
        };
      }
    }
  }
});

Build Prerequisites

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:

  1. Install msysgit (Full installer for official Git), GNU make for Windows, and a binary version of Node.js. Make sure all three packages are installed to the same location (by default, this is C:\Program Files\Git).
  2. Install Cygwin (make sure you install the git, make, and which packages), then either follow the Node.js build instructions or install the binary version of Node.js.

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.

Building jStat

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.

Running Tests

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.

Get the Code

Both the minified and unminified source are located in the dist/ directory. For those who don't want to build it themselves.

Contribute

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.

Join the Community

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.