Modern statistical computing for JavaScript
A lightweight, high-performance statistics library built for modern development. Zero dependencies, full TypeScript support, and blazingly fast algorithms optimized for real-world data analysis.
Built for performance and developer experience
Uses Quickselect algorithm for median calculation. 5-10x faster than sort-based implementations on large datasets.
Built with TypeScript from day one. Full type inference and compile-time safety out of the box.
Zero dependencies. Just 3.7KB minified. Won't bloat your bundle size.
Modern ESM support. Import only what you need for optimal bundling.
Works with arrays of numbers or objects. Extract values by key effortlessly.
Comprehensive error handling and edge case coverage for production use.
Get started in seconds with our simple API
import statistics from 'mintstats';
const scores = [85, 92, 78, 90, 88];
// Calculate basic statistics
const avg = statistics.mean(scores); // 86.6
const mid = statistics.median(scores); // 88
const spread = statistics.stdev(scores); // 5.22
const range = statistics.range(scores); // 14
import statistics from 'mintstats';
const students = [
{ name: 'Alice', score: 85 },
{ name: 'Bob', score: 92 },
{ name: 'Charlie', score: 78 },
{ name: 'Diana', score: 90 }
];
// Extract and calculate from object property
const avgScore = statistics.mean(students, 'score'); // 86.25
const medianScore = statistics.median(students, 'score'); // 87.5
const p75 = statistics.percentile(students, 75, 'score'); // 90.5
import statistics from 'mintstats';
const data = [2, 4, 6, 8, 10];
// Sample variance (default, n-1)
const sampleVar = statistics.variance(data);
// 10
// Population variance (n)
const popVar = statistics.variance(data, { isSample: false });
// 8
// With objects
const employees = [
{ name: 'John', salary: 50000 },
{ name: 'Jane', salary: 60000 }
];
const salaryStdev = statistics.stdev(employees, {
key: 'salary',
isSample: true
});
Complete documentation of all available functions
Calculates the arithmetic mean (average) of the data.
statistics.mean([10, 20, 30]); // 20
Calculates the median using Quickselect algorithm. O(n) average time complexity.
statistics.median([10, 20, 30, 40]); // 25
Returns an array of the most frequently occurring value(s).
statistics.mode([1, 2, 2, 3]); // [2]
Calculates the range (difference between max and min).
statistics.range([10, 20, 30]); // 20
Calculates the variance (sample or population).
statistics.variance([2, 4, 6], { isSample: false });
Calculates the standard deviation (sample or population).
statistics.stdev([2, 4, 6, 8]); // 2.58
Calculates the nth percentile (0-100) using linear interpolation.
statistics.percentile([10, 20, 30, 40, 50], 75); // 40