@basementuniverse/stats
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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).

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

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
}

Package Sidebar

Install

npm i @basementuniverse/stats

Weekly Downloads

116

Version

1.1.1

License

MIT

Unpacked Size

32.1 kB

Total Files

12

Last publish

Collaborators

  • basementuniverse