# JavaScript statistics libraries

JavaScript statistics libraries compute summaries such as the mean, variance, and quantiles, and work with probability distributions. Distribution functions return probabilities from a distribution or draw random samples from it. These libraries let dashboards, analytics tools, and AI agents describe data and run regressions in the browser or Node.js.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [d3-array](#d-array) | 552.6M | 464 | Nov 2026 | ISC |
| [d3-random](#dthree-random) | 125.8M | 139 | Nov 2026 | ISC |
| [Math.js](#mathjs) | 21.3M | 15.1K | Apr 2026 | Apache-2.0 |
| [ml-matrix](#ml-matrix) | 8.2M | 403 | Oct 2026 | MIT |
| [vega-statistics](#vega-statistics) | 7.7M | 12.0K | Mar 2025 | BSD-3-Clause |
| [jStat](#jstat) | 6.0M | 1.8K | Nov 2022 | MIT |
| [Simple Statistics](#simple-statistics) | 5.3M | 3.5K | Oct 2026 | ISC |
| [@tensorflow/tfjs](#tensorflow-tfjs) | 2.4M | 19.2K | Oct 2024 | Apache-2.0 |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[d3-array](#d-array) has the most monthly downloads in this comparison, at 538.9M.

## Capabilities

| Library | Sample SD | Normal CDF | Normal sampling |
| --- | --- | --- | --- |
| [d3-array](#d-array) | Yes | No | No |
| [d3-random](#dthree-random) | No | No | Yes |
| [Math.js](#mathjs) | Yes | No | No |
| [ml-matrix](#ml-matrix) | Yes | No | No |
| [vega-statistics](#vega-statistics) | No | Yes | Yes |
| [jStat](#jstat) | Yes | Yes | Yes |
| [Simple Statistics](#simple-statistics) | Yes | Yes | No |
| [@tensorflow/tfjs](#tensorflow-tfjs) | No | No | Yes |

## Libraries

### d3-array

[GitHub](https://github.com/d3/d3-array) · [npm](https://www.npmjs.com/package/d3-array) · [Docs](https://d3js.org/d3-array)

Provides array summarization, ordering, grouping, and other data operations.

- Downloads / mo: 552.6M
- Stars: 464
- Last release: 3.2.5
- License: ISC
- Capabilities: [From the d3-array docs](https://d3js.org/d3-array)

**Strengths**

- **Skips missing values in means.** Mean ignores null, undefined, and NaN values.
- **Summarizes records through accessors.** Select a numeric field without manually constructing another input array.

**Watch out for**

- **Variance needs multiple numeric values.** Variance returns undefined when fewer than two numeric values remain.
- **quantileSorted needs sorted input.** Sort the input first or use the regular quantile function.

```sh
npm install d3-array
```

**keplergl/kepler.gl** (12.1K stars)

[keplergl/kepler.gl](https://github.com/keplergl/kepler.gl) 

```javascript
function getNumericStats(values: readonly unknown[]): NumericColumnStats {
  const filtered = values.filter(isNumber);
  quickInsertionSort(filtered);

  const quantiles = QUANTILE_STOPS.map(p => ({
    label: p === 0 ? 'Min' : p === 1 ? 'Max' : `${p * 100}%`,
    value: filtered.length ? quantileSorted(filtered, p) ?? null : null
  }));

  return {
    type: ColumnStatsType.numeric,
    bins: histogramFromValues(filtered, NUMERIC_BIN_COUNT),
    quantiles,
    percentNulls: percentNulls(values.length, filtered.length),
    mean: filtered.length ? mean(filtered) ?? null : null,
    std: filtered.length ? deviation(filtered) ?? null : null
  };
}

```

[src/utils/src/column-statistics.ts](https://github.com/keplergl/kepler.gl/blob/19321a80882c73b46dc2296e117d9734b0b4cd18/src/utils/src/column-statistics.ts#L76-L93) · [More projects using d3-array →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20d3-array%20for%20table%20summaries%2C%20statistical%20formula%20integration%2C%20numeric%20validation%20and%20row%20or%20column%20statistics&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import { deviation } from 'd3-array';

console.log(deviation([1, 2, 3]));

```

From [README.md](https://github.com/d3/d3-array/blob/main/src/index.js)

### d3-random

[GitHub](https://github.com/d3/d3-random) · [npm](https://www.npmjs.com/package/d3-random) · [Docs](https://d3js.org/d3-random)

Generates random numbers from various distributions.

- Downloads / mo: 125.8M
- Stars: 139
- Last release: 3.0.2
- License: ISC
- Capabilities: [From the d3-random docs](https://d3js.org/d3-random)

```sh
npm install d3-random
```

**d3fc/d3fc** (1.4K stars)

[d3fc/d3fc](https://github.com/d3fc/d3fc) 

```javascript
var geometricBrownianMotion = (value = 0) => {
    const timeStep = period / steps;
    const pathData = [];

    for (let i = 0; i < steps + 1; i++) {
        pathData.push(value);
        const increment = (random() * Math.sqrt(timeStep) * sigma) +
            ((mu - sigma * sigma / 2) * timeStep);
        value = value * Math.exp(increment);
    }

    return pathData;
};

```

[packages/d3fc-random-data/src/geometricBrownianMotion.js](https://github.com/d3fc/d3fc/blob/55ee5942a0885ea073838afaaa89eba24cefab15/packages/d3fc-random-data/src/geometricBrownianMotion.js#L10-L22) · [More projects using d3-random →](https://dashboard.exa.ai/playground/search?q=d3-random%20GitHub%20projects)

**Quickstart**

```javascript
import { randomNormal } from 'd3-random';

const draw = randomNormal(0, 1);
console.log(draw());

```

From [normal.js](https://github.com/d3/d3-random/blob/main/src/index.js)

### Math.js

[GitHub](https://github.com/josdejong/mathjs) · [npm](https://www.npmjs.com/package/mathjs) · [Docs](https://mathjs.org)

Provides statistical functions within a broader mathematics library.

- Downloads / mo: 21.3M
- Stars: 15.1K
- Last release: 15.2.0
- License: Apache-2.0
- Capabilities: [From the Math.js docs](https://mathjs.org)

**Strengths**

- **Calculates across matrix dimensions.** Compute variance over all values or along rows and columns.
- **Supports typed quantile inputs.** Compute quantiles from Number, BigNumber, and Unit sequences.

**Watch out for**

- **Mean flattens multidimensional inputs.** Specify a dimension when the result should summarize rows or columns.
- **Variance uses sample normalization initially.** Choose uncorrected normalization for population variance.

```sh
npm install mathjs
```

**javascriptdata/danfojs** (5.1K stars)

[javascriptdata/danfojs](https://github.com/javascriptdata/danfojs) 

```javascript
median(options?: { axis?: 0 | 1 }): Series {
    const { axis } = { axis: 1, ...options }

    if (this.$frameIsNotCompactibleForArithmeticOperation()) {
        throw Error("TypeError: median operation is not supported for string dtypes");
    }

    if ([0, 1].indexOf(axis) === -1) {
        throw Error("ParamError: Axis must be 0 or 1");
    }

    const newData = this.$getDataByAxisWithMissingValuesRemoved(axis)
    const resultArr = newData.map(arr => median(arr))
    if (axis === 0) {
        return new Series(resultArr, { index: this.columns });
    } else {
        return new Series(resultArr, { index: this.index });
    }

}

```

[src/danfojs-base/core/frame.ts](https://github.com/javascriptdata/danfojs/blob/21d8c550b3aeba5f5ef0b46227a750307e203e70/src/danfojs-base/core/frame.ts#L859-L878) · [More projects using Math.js →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20mathjs%20for%20table%20summaries%2C%20statistical%20formula%20integration%2C%20numeric%20validation%20and%20row%20or%20column%20statistics&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import { std } from 'mathjs';

console.log(std([1, 2, 3]));

```

From [variance.html](https://mathjs.org/docs/reference/functions/std.html)

### ml-matrix

[GitHub](https://github.com/mljs/matrix) · [npm](https://www.npmjs.com/package/ml-matrix) · [Docs](https://mljs.github.io/matrix/)

Manipulates and computes matrices.

- Downloads / mo: 8.2M
- Stars: 403
- Last release: 6.15.1
- License: MIT
- Capabilities: [From the ml-matrix docs](https://mljs.github.io/matrix/)

```sh
npm install ml-matrix
```

**mljs/pca** (104 stars)

[mljs/pca](https://github.com/mljs/pca) 

```javascript
private _adjust(dataset: Matrix, ignoreZeroVariance: boolean) {
  if (this.center) {
    const mean = dataset.mean('column');
    const stdevs = this.scale
      ? dataset.standardDeviation('column', { mean })
      : null;
    this.means = mean;
    dataset.subRowVector(mean);
    if (this.scale) {
      for (let i = 0; i < (stdevs as number[]).length; i++) {
        if ((stdevs as number[])[i] === 0) {
          if (ignoreZeroVariance) {
            dataset.removeColumn(i);
            (stdevs as number[]).splice(i, 1);
            this.excludedFeatures.push(i);
            i--;
          } else {
            throw new RangeError(
              `Cannot scale the dataset (standard deviation is zero at index ${i}`,
            );
          }
        }
      }
      this.stdevs = stdevs;
      dataset.divRowVector(stdevs as number[]);
    }
  }
}

```

[src/pca.ts](https://github.com/mljs/pca/blob/5a90019338acbc7ea79b3fc23c4f0b76aa2be327/src/pca.ts#L282-L309) · [More projects using ml-matrix →](https://dashboard.exa.ai/playground/search?q=ml-matrix%20GitHub%20projects)

**Quickstart**

```javascript
import { Matrix } from 'ml-matrix';

const matrix = Matrix.ones(5, 5);

```

From [README.md](https://github.com/mljs/matrix/blob/main/README.md)

### vega-statistics

[GitHub](https://github.com/vega/vega) · [npm](https://www.npmjs.com/package/vega-statistics) · [Docs](https://vega.github.io/vega)

Provides statistical routines and probability distributions.

- Downloads / mo: 7.7M
- Stars: 12.0K
- Last release: 2.0.0
- License: BSD-3-Clause
- Capabilities: [From the vega-statistics docs](https://vega.github.io/vega)

```sh
npm i vega-statistics
```

**cmudig/falcon-vis** (110 stars)

[cmudig/falcon-vis](https://github.com/cmudig/falcon-vis) 

```javascript
export function binContinuous(
  maxbins: number,
  extent: Interval<number>,
  exact = false
): BinConfig {
  // will do exactly max bins
  if (exact) {
    return binRegularIntervals(maxbins, extent);
  }

  // might do bins less than maxbins, but will do it more nicely intervals
  return vegaBin({ maxbins, extent });
}

```

[falcon-vis/src/util.ts](https://github.com/cmudig/falcon-vis/blob/1df0856d8098ce209d949d4f7652623847ab6f31/falcon-vis/src/util.ts#L71-L83) · [More projects using vega-statistics →](https://dashboard.exa.ai/playground/search?q=vega-statistics%20GitHub%20projects)

**Quickstart**

```javascript
import { bin } from 'vega-statistics';

const bins = bin({ extent: [0, 10], maxbins: 5 });
console.log(bins);

```

From [bin.js](https://github.com/vega/vega/blob/main/packages/vega-statistics/index.js)

### jStat

[GitHub](https://github.com/jstat/jstat) · [npm](https://www.npmjs.com/package/jstat) · [Docs](http://jstat.github.io/)

Provides statistical operations through static functions and wrapped numeric collections.

- Downloads / mo: 6.0M
- Stars: 1.8K
- Last release: 1.9.6
- License: MIT
- Capabilities: [From the jStat docs](http://jstat.github.io/)

**Strengths**

- **Configures quantile estimation.** Set the quantile parameters to match the required estimation method.
- **Offers static and wrapped APIs.** Use static functions or chain operations on a jStat object.

**Watch out for**

- **Variance defaults to the population.** Pass true for sample variance when using the array API.
- **Matrix variance restricts sample selection.** The matrix API cannot select population versus sample variance through its flag.

```sh
npm install --save jstat
```

**Quickstart**

```javascript
const { jStat } = require('jstat');

console.log(jStat.mean([1, 2, 3]));

```

From [overview.md](https://github.com/jstat/jstat/blob/1.x/src/vector.js) · [Find projects using jStat →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20jstat%20for%20table%20summaries%2C%20statistical%20formula%20integration%2C%20numeric%20validation%20and%20row%20or%20column%20statistics&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### Simple Statistics

[GitHub](https://github.com/simple-statistics/simple-statistics) · [npm](https://www.npmjs.com/package/simple-statistics) · [Docs](https://simple-statistics.github.io/)

Provides descriptive, regression, and inference statistics.

- Downloads / mo: 5.3M
- Stars: 3.5K
- Last release: 8.0.0
- License: ISC
- Capabilities: [From the Simple Statistics docs](https://simple-statistics.github.io/)

**Strengths**

- **Separates sample and population variance.** Choose variance for populations or sampleVariance for samples.
- **Computes sample correlations.** Measure linear association between paired datasets with sampleCorrelation.

**Watch out for**

- **Quantiles assume a complete population.** Use its population quantile convention when comparing results across tools.

```sh
npm install simple-statistics
```

**Quickstart**

```javascript
import { min } from 'simple-statistics';

console.log(min([1, 2, 3]));

```

From [README.md](https://github.com/simple-statistics/simple-statistics/blob/main/index.d.ts) · [Find projects using Simple Statistics →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20simple-statistics%20for%20table%20summaries%2C%20statistical%20formula%20integration%2C%20numeric%20validation%20and%20row%20or%20column%20statistics&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### @tensorflow/tfjs

[GitHub](https://github.com/tensorflow/tfjs) · [npm](https://www.npmjs.com/package/@tensorflow/tfjs) · [Docs](https://js.tensorflow.org)

Provides an open-source machine learning framework.

- Downloads / mo: 2.4M
- Stars: 19.2K
- Last release: 4.22.0
- License: Apache-2.0
- Capabilities: [From the @tensorflow/tfjs docs](https://js.tensorflow.org)

```sh
npm install @tensorflow/tfjs
```

**tensorflow/tfjs-examples** (6.8K stars)

[tensorflow/tfjs-examples](https://github.com/tensorflow/tfjs-examples) 

```javascript
export function determineMeanAndStddev(data) {
  const dataMean = data.mean(0);
  // TODO(bileschi): Simplify when and if tf.var / tf.std added to the API.
  const diffFromMean = data.sub(dataMean);
  const squaredDiffFromMean = diffFromMean.square();
  const variance = squaredDiffFromMean.mean(0);
  const dataStd = variance.sqrt();
  return {dataMean, dataStd};
}

```

[boston-housing/normalization.js](https://github.com/tensorflow/tfjs-examples/blob/51430d697acd332f9d89fefe6df2fd90537d9e96/boston-housing/normalization.js#L27-L35) · [More projects using @tensorflow/tfjs →](https://dashboard.exa.ai/playground/search?q=%40tensorflow/tfjs%20GitHub%20projects)

**Quickstart**

```javascript
import * as tf from '@tensorflow/tfjs';

await tf.ready();
const values = tf.tensor1d([1, 2, 3]);
const { mean, variance } = tf.moments(values);
mean.print();
variance.print();
tf.dispose([values, mean, variance]);

```

From [moments.ts](https://github.com/tensorflow/tfjs/blob/master/README.md)

## FAQ

### Which JavaScript statistics library should I use?

[Simple Statistics](#simple-statistics) suits apps that need descriptive statistics, regression, and inference tests in one package. [jStat](#jstat) suits code that needs named probability distributions alongside descriptive statistics. [d3-array](#d-array) suits data pipelines that need summaries and quantiles.

### Sample vs population standard deviation: what is the difference?

Sample standard deviation divides by one less than the number of values to correct the bias of estimating from a sample. Population standard deviation divides by the full count. [Math.js](#mathjs) switches between the two with a setting.

### What is jStat?

[jStat](#jstat) provides statistical routines for arrays and matrices along with named probability distribution functions. It computes values such as the normal CDF.

### How do I generate normally distributed random numbers in JavaScript?

[d3-random](#dthree-random) generates random numbers from the normal distribution and other distributions. [jStat](#jstat) and [Vega Statistics](#vega-statistics) also sample from a normal distribution.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript statistics libraries simple-statistics jStat d3-array mathjs examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
