jStat: JavaScript Statistical Library

1.9.6 · abandoned · verified Sun Apr 19

jStat is a comprehensive JavaScript library providing native implementations of statistical functions, suitable for both browser and Node.js environments. It stands out for offering a wide array of functions for various probability distributions, including Weibull, Cauchy, Poisson, Hypergeometric, and Beta, which are often not found in other similar libraries. For most distributions, jStat includes functions for PDF, CDF, inverse CDF, mean, mode, variance, and sampling. The current stable version is 1.9.6, last published four years ago, indicating a slower release cadence and suggesting potential abandonment. A key point of confusion is its module export structure, exposing `jStat` and `j$` properties within an object rather than as direct exports, which requires specific handling for module loaders like CommonJS and for ESM interoperability. The library also emphasizes browser usage, making the `jStat` object globally available.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing jStat, calculating basic statistics (mean, standard deviation) from a dataset, using a normal distribution's CDF, and generating a random sample.

import * as jStatModule from 'jstat';
const jStat = jStatModule.jStat;

// Define a dataset
const dataset = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Calculate mean and standard deviation
const mean = jStat(dataset).mean();
const stdev = jStat(dataset).stdev();

console.log(`Dataset: [${dataset.join(', ')}]`);
console.log(`Mean: ${mean}`);
console.log(`Standard Deviation: ${stdev}`);

// Example of using a distribution function: Normal CDF
const normalDist = jStat.normal(mean, stdev);
const cdfAt7 = normalDist.cdf(7);
console.log(`CDF at x=7 for Normal(${mean.toFixed(2)}, ${stdev.toFixed(2)}): ${cdfAt7.toFixed(4)}`);

// Example of generating a sample
const sample = normalDist.sample(5);
console.log(`Random sample of 5 from Normal(${mean.toFixed(2)}, ${stdev.toFixed(2)}): [${sample.map(s => s.toFixed(2)).join(', ')}]`);

view raw JSON →