Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/basementuniverse/stats
Basic statistics functions
https://github.com/basementuniverse/stats
Last synced: 23 days ago
JSON representation
Basic statistics functions
- Host: GitHub
- URL: https://github.com/basementuniverse/stats
- Owner: basementuniverse
- License: mit
- Created: 2022-06-12T21:08:36.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-19T08:30:07.000Z (5 months ago)
- Last Synced: 2024-12-12T12:17:06.864Z (27 days ago)
- Language: TypeScript
- Size: 429 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 bucketWithin 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
}
]
```