Home Reference Source Repository

Function

Static Public Summary
public

Choose k elements from a set of n elements.

public

A useful function.

public

n! is the product of all positive integers less than or equal to n.

public

The gamma function is a useful general function.

public

The regularized lower incomplete gamma function See

public

The log-gamma function is a useful general function.

public

Averages a list of elements.

public

Finds the central most value for a list of numbers.

public

Finds the most frequent values of a list of numbers.

public

Finds the element of a list of numbers at a certain percentile ordered smallest to largest.

public

quantile(x: Array<number>, quantiles: Array<number>): number

Finds the nth largest element of a list of numbers.

public

Finds the difference between the largest and smallest values.

public

select(x: Array<number>, k: number, begin: number, end: number): number

Efficiently finds the kth largest element in a array.

public

A measure that is used to quantify the amount of variation of a set of data values.

public

Efficiently appoximates ln(n!).

public

Adds a list of elements together.

public

A really useful function.

public

ttest(sample: Sample, other: Sample, x: number): number

Computes Student's T-Test for the provided samples. If only one sample is provided, a one-sample t-test is computed on the sample mean vs x. If two samples are provided, a two-sample t-test is computed on the difference between the sample means and x. See: Student's T-Test

public

A measure that is used to quantify the amount of variation of a set of data values from their mean value.

public

zscore(x: number, mu: number, std: number): number

The signed number of deviations an observed value is above the mean.

Static Public

public choose(n: number, k: number): number source

import choose from 'sampson/lib/utils/choose.js'

Choose k elements from a set of n elements. See: Binomial Coefficient

Params:

NameTypeAttributeDescription
n number

The number of elements to choose from.

k number

The number of elements to choose.

Return:

number

A binomial coefficient or NaN if n < k.

public error(x: number): number source

import error from 'sampson/lib/utils/error.js'

A useful function. Gets used in the Normal distribution cdf. It's the probability of a random variable with normal distribution of mean 0 and variance 1/2 falling in the range [-x, x]. See: Error

Params:

NameTypeAttributeDescription
x number

The numbers to average.

Return:

number

The error value.

public factorial(n: number): number source

import factorial from 'sampson/lib/utils/factorial.js'

n! is the product of all positive integers less than or equal to n. See

Params:

NameTypeAttributeDescription
n number

The number.

Return:

number

n!, or 1 if n == 0, or Inifinity if n > ~170, or NaN if n < 0.

public gamma(n: number): number source

import gamma from 'sampson/lib/utils/gamma.js'

The gamma function is a useful general function. It's (n - 1)!. See

Params:

NameTypeAttributeDescription
n number

The number.

Return:

number

An approximation of (n-1)! or Infinity if n is a negative integer.

public gammainc_lower(s: number, z: number): number source

import gammainc_lower from 'sampson/lib/utils/gammainc.js'

The regularized lower incomplete gamma function See

Params:

NameTypeAttributeDescription
s number

The first number.

z number

The second number.

Return:

number

The value from the lower incomplete gamma function.

public lngamma(z: number): number source

import lngamma from 'sampson/lib/utils/lngamma.js'

The log-gamma function is a useful general function. It can handle much larger numbers because it grows much slower compared to the gamma function. It's (n - 1)! and is used by the gamma function for n > 100. See

Params:

NameTypeAttributeDescription
z number

The number.

Return:

number

An approximation of ln(n-1)! or NaN if n < 0.

public mean(x: Array<number>): number source

import mean from 'sampson/lib/utils/mean.js'

Averages a list of elements. Uses our internal sum function. See: Mean

Params:

NameTypeAttributeDescription
x Array<number>

The numbers to average.

Return:

number

The mean or NaN if x is the empty set.

public median(x: Array<number>): number source

import median from 'sampson/lib/utils/median.js'

Finds the central most value for a list of numbers. If the list is even, and has no single center, the two inner-most values are averaged. Uses our internal selection function. See: Median

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

Return:

number

The median or NaN if x is the empty set.

public mode(x: Array<number>): number source

import mode from 'sampson/lib/utils/mode.js'

Finds the most frequent values of a list of numbers. It always returns an array. The result may contain one or more values. See: Mode

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

Return:

number

The mode or NaN if x is the empty set.

public percentile(x: Array<number>, p: number): number source

import percentile from 'sampson/lib/utils/percentile.js'

Finds the element of a list of numbers at a certain percentile ordered smallest to largest. Uses the internal select function. See: List Ranking

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

p number

The percentile.

Return:

number

The element at the pth percentile of x or NaN if x is the empty set.

public quantile(x: Array<number>, quantiles: Array<number>): number source

import quantile from 'sampson/lib/utils/quantile.js'

Finds the nth largest element of a list of numbers. Accepts both a single quantile and an array of quantiles. See: List Ranking

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

quantiles Array<number>

A list of quantiles to compute.

Return:

number

The computed quantiles respective to quantiles provided or NaN if x is the empty set.

public range(x: Array<number>): number source

import range from 'sampson/lib/utils/range.js'

Finds the difference between the largest and smallest values. See: Range)

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

Return:

number

The range or NaN if x is the empty set.

public select(x: Array<number>, k: number, begin: number, end: number): number source

import select from 'sampson/lib/utils/select.js'

Efficiently finds the kth largest element in a array. See: Selection

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

k number

The element to select.

begin number
  • optional

The starting index.

end number
  • optional

The ending index.

Return:

number

The kth largest element or NaN if x is the empty set.

public std(x: Array<number>): number source

import std from 'sampson/lib/utils/std.js'

A measure that is used to quantify the amount of variation of a set of data values. See: Standard Deviation

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

Return:

number

The standard deviation or 0 if x is the empty set.

public stirling(n: number): number source

import stirling from 'sampson/lib/utils/stirling.js'

Efficiently appoximates ln(n!). Similar to the gamma function, but can be faster and more accurate. See: Stirling's Approximation

Params:

NameTypeAttributeDescription
n number

The number.

Return:

number

An approximation on ln(n!).

public sum(x: Array<number>): number source

import sum from 'sampson/lib/utils/sum.js'

Adds a list of elements together. Uses the Kahan summation algorithm to compensate for floating-point error. See: Summation

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

Return:

number

The sum or 0 if x is the empty set.

public sumNthPowerDev(x: Array<number>, n: number, absolute: boolean): number source

import sumNthPowerDev from 'sampson/lib/utils/sumnthpowerdev.js'

A really useful function. Takes a set of observations and returns the sum of the difference of each observation and the mean of the set raised to the nth power. Can be used to find the absolute value of the difference for functions like MeanDeviation, or by default, the signed values for functions like Variance and SquaredMeanDeviation.

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

n number

The number to raise to.

absolute boolean
  • optional
  • default: false

Use absolute value of difference.

Return:

number

The sum of (x-mu)^n or NaN if x is the empty set.

public ttest(sample: Sample, other: Sample, x: number): number source

Computes Student's T-Test for the provided samples. If only one sample is provided, a one-sample t-test is computed on the sample mean vs x. If two samples are provided, a two-sample t-test is computed on the difference between the sample means and x. See: Student's T-Test

Params:

NameTypeAttributeDescription
sample Sample

The sample to test

other Sample
  • optional

An optional sample to compare with a two sample test.

x number
  • optional
  • default: 0

The mean or difference to test.

Return:

number

The t-statistic or NaN if the sample is the empty set.

public variance(x: Array<number>): number source

import variance from 'sampson/lib/utils/variance.js'

A measure that is used to quantify the amount of variation of a set of data values from their mean value. See: Variance

Params:

NameTypeAttributeDescription
x Array<number>

The numbers.

Return:

number

The variance or NaN if x is the empty set.

public zscore(x: number, mu: number, std: number): number source

import zscore from 'sampson/lib/utils/zscore.js'

The signed number of deviations an observed value is above the mean. See: Standard Score

Params:

NameTypeAttributeDescription
x number

The number.

mu number

The mean.

std number

The standard deviation.

Return:

number

The zscore.