Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/basementuniverse/stats

Basic statistics functions
https://github.com/basementuniverse/stats

Last synced: 23 days ago
JSON representation

Basic statistics functions

Awesome Lists containing this project

README

        

# Stats

Basic stats functions

## Installation

```
npm install @basementuniverse/stats
```

## Usage

Node:

```javascript
const {
mean,
median,
mode,
range,
variance,
standardDeviation,
iqr,
outliers,
histogram,
} = require('@basementuniverse/stats');
```

Typescript:

```typescript
import {
mean,
median,
mode,
range,
variance,
standardDeviation,
iqr,
outliers,
histogram,
} from '@basementuniverse/stats';
```

## Docs

## Functions



minArray(a)number


Safe version of Math.min


Native Math.min throws:


`Uncaught RangeError: Maximum call stack size exceeded`


when passing in a huge number of arguments (>~100k).




maxArray(a)number


Safe version of Math.max


Native Math.max throws:


`Uncaught RangeError: Maximum call stack size exceeded`


when passing in a huge number of arguments (>~100k).




mean(data)number


Find the mean of a list of numbers




median(data)number


Find the median of a list of numbers




mode(data)number


Find the mode of a list of numbers




range(data)object


Find the range of a list of numbers




variance(data, sample)number


Calculate the variance of a list of numbers




standardDeviation(data, sample)number


Calculate the standard deviation of a list of numbers




iqr(data)object


Calculate the (exclusive) interquartile range of a list of numbers




outliers(data)Array.<number>


Find outliers in a list of numbers using the IQR method




histogram(data, bucketWidth)Array.<Bucket>


Generate a histogram by splitting data into buckets of the specified size
and counting the frequency of items in each bucket


Within each bucket, min is inclusive and max is exclusive



## minArray(a) ⇒ number
Safe version of `Math.min`

Native `Math.min` throws:
```
`Uncaught RangeError: Maximum call stack size exceeded`
```
when passing in a huge number of arguments (>~100k).

**Kind**: global function
**Returns**: number - The minimum number from the array

| Param | Type | Description |
| --- | --- | --- |
| a | Array.<number> | An array of numbers |

## maxArray(a) ⇒ number
Safe version of `Math.max`

Native `Math.max` throws:
```
`Uncaught RangeError: Maximum call stack size exceeded`
```
when passing in a huge number of arguments (>~100k).

**Kind**: global function
**Returns**: number - The maximum number from the array

| Param | Type | Description |
| --- | --- | --- |
| a | Array.<number> | An array of numbers |

## mean(data) ⇒ number
Find the mean of a list of numbers

**Kind**: global function
**Returns**: number - The mean of a list of numbers

| Param | Type | Description |
| --- | --- | --- |
| data | Array.<number> | An array of numbers |

## median(data) ⇒ number
Find the median of a list of numbers

**Kind**: global function
**Returns**: number - The median of a list of numbers

| Param | Type | Description |
| --- | --- | --- |
| data | Array.<number> | An array of numbers |

## mode(data) ⇒ number
Find the mode of a list of numbers

**Kind**: global function
**Returns**: number - The mode of a list of numbers

| Param | Type | Description |
| --- | --- | --- |
| data | Array.<number> | An array of numbers |

## range(data) ⇒ object
Find the range of a list of numbers

**Kind**: global function
**Returns**: object - An object containing the min, max and range

| Param | Type | Description |
| --- | --- | --- |
| data | Array.<number> | An array of numbers |

**Example**
Returned format:
```
{
min: 1,
max: 5,
range: 4
}
```

## variance(data, sample) ⇒ number
Calculate the variance of a list of numbers

**Kind**: global function
**Returns**: number - The variance of a list of numbers

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| data | Array.<number> | | An array of numbers |
| sample | boolean | false | True if the dataset is a sample |

## standardDeviation(data, sample) ⇒ number
Calculate the standard deviation of a list of numbers

**Kind**: global function
**Returns**: number - The standard deviation of a list of numbers

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| data | Array.<number> | | An array of numbers |
| sample | boolean | false | True if the dataset is a sample |

## iqr(data) ⇒ object
Calculate the (exclusive) interquartile range of a list of numbers

**Kind**: global function
**Returns**: object - An object containing the Q1, Q2 and Q3 medians and interquartile range

| Param | Type | Description |
| --- | --- | --- |
| data | Array.<number> | An array of numbers |

**Example**
Returned format:
```
{
q1: 1,
q2: 3,
q3: 5,
range: 4
}
```

## outliers(data) ⇒ Array.<number>
Find outliers in a list of numbers using the IQR method

**Kind**: global function
**Returns**: Array.<number> - An array of indexes for the outliers

| Param | Type | Description |
| --- | --- | --- |
| data | Array.<number> | An array of numbers |

## histogram(data, bucketWidth) ⇒ Array.<Bucket>
Generate a histogram by splitting data into buckets of the specified size
and counting the frequency of items in each bucket

Within each bucket, min is inclusive and max is exclusive

**Kind**: global function
**Returns**: Array.<Bucket> - An array of buckets

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| data | Array.<number> | | An array of numbers |
| bucketWidth | number | 1 | The width of each bucket |

**Example**
Returned format:
```
[
{
min: 1,
max: 3,
frequency: 4
}
]
```