An open API service indexing awesome lists of open source software.

https://github.com/peakk2011/mintstats

Javascript library for statistical calculations
https://github.com/peakk2011/mintstats

data-science data-structures-and-algorithms javascript-data-structures javascript-library library maths peakk2011 static statistics statistics-programming

Last synced: 16 days ago
JSON representation

Javascript library for statistical calculations

Awesome Lists containing this project

README

          

# Mint Statistics

A lightweight and fast statistics library for JavaScript and TypeScript.

## Why Mint Stats?

- **5-10x faster** than traditional implementations (Quickselect for median)
- **Fully typed** - Built with TypeScript from the ground up
- **Zero dependencies** - Size: 3.7KB
- **Tree-shakeable** - Import only what you need

## Install

```bash
npm install mintstats
```

## Quick Start

```javascript
import statistics from "mintstats";

const scores = [85, 92, 78, 90, 88];

statistics.mean(scores); // 86.6
statistics.median(scores); // 88
statistics.stdev(scores); // 5.22

// Works with objects too
const students = [
{ name: "Alice", score: 85 },
{ name: "Bob", score: 92 },
];

statistics.mean(students, "score"); // 88.5
statistics.percentile(students, 75, "score"); // 90.5
```

## API

**Basic Stats**

- `mean(arr, key?)` - Average
- `median(arr, key?)` - Middle value (uses Quickselect - O(n))
- `mode(arr, key?)` - Most frequent value(s)
- `range(arr, key?)` - Max - Min

**Variability**

- `variance(arr, options?)` - Variance (sample or population)
- `stdev(arr, options?)` - Standard deviation
- `percentile(arr, p, key?)` - Nth percentile (0-100)

**Options** for variance/stdev:

```javascript
{
key: 'propertyName', // for object arrays
isSample: true // sample (n-1) or population (n)
}
```

## Performance

Benchmark on 10,000 items:

```
Traditional (sort): 588 ops/sec
Mint Stats: 3,438 ops/sec -> 5.85x faster
```

## TypeScript

Full type safety with automatic inference:

```typescript
statistics.mean([1, 2, 3]); // Works
statistics.mean(objects, "value"); // Works
statistics.mean(objects); // Type error - key required
```

## License

MIT © Peakk