1.3.0 • Published 11 months ago

@basementuniverse/stats v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Stats

Basic stats functions

Installation

npm install @basementuniverse/stats

Usage

Node:

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

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

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

ParamTypeDescription
aArray.<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

ParamTypeDescription
aArray.<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

ParamTypeDescription
dataArray.<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

ParamTypeDescription
dataArray.<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

ParamTypeDescription
dataArray.<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

ParamTypeDescription
dataArray.<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

ParamTypeDefaultDescription
dataArray.<number>An array of numbers
samplebooleanfalseTrue 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

ParamTypeDefaultDescription
dataArray.<number>An array of numbers
samplebooleanfalseTrue 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

ParamTypeDescription
dataArray.<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

ParamTypeDescription
dataArray.<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

ParamTypeDefaultDescription
dataArray.<number>An array of numbers
bucketWidthnumber1The width of each bucket

Example
Returned format:

[
  {
    min: 1,
    max: 3,
    frequency: 4
  }
]
1.2.0

11 months ago

1.3.0

11 months ago

1.1.1

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago