@basementuniverse/stats
v1.1.1
Published
Basic statistics functions
Downloads
159
Maintainers
Readme
Stats
Basic stats functions
Installation
npm install @basementuniverse/stats
Usage
Node:
const {
mean,
median,
mode,
range,
variance,
standardDeviation,
iqr,
} = require('@basementuniverse/stats');
Typescript:
import {
mean,
median,
mode,
range,
variance,
standardDeviation,
iqr,
} 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).
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
}