what is this?

A small library for robust generation of various random variates, testing data against distributions or calculating different statistical properties.

install in node

npm install --save ranjs

use in browser

<script type="text/javascript" src="ran.min.js"></script>

demo

Continuous distributions

documentation

ran.core.char([string[, n]])
Samples some characters with replacement from a string with uniform distribution.

Parameters

NameTypeDescription
stringstringString to sample characters from.
nnumberNumber of characters to sample.

Returns

stringstring[]undefined
Random character if n is not given or less than 2, an array of random characters otherwise. If string is empty, undefined is returned.

Examples

ran.core.char('abcde')
// => 'd'

ran.core.char('abcde', 5)
// => [ 'd', 'c', 'a', 'a', 'd' ]
ran.core.choice([values[, n]])
Samples some elements with replacement from an array with uniform distribution.

Parameters

NameTypeDescription
valuesArrayArray to sample from.
nnumberNumber of elements to sample.

Returns

objectobject[]undefined
Single element or array of sampled elements. If the array is invalid (empty or not passed), undefined is returned.

Examples

ran.core.choice([1, 2, 3, 4, 5])
// => 2

ran.core.choice([1, 2, 3, 4, 5], 5)
// => [ 1, 5, 4, 4, 1 ]
ran.core.coin(head, tail[, p[, n]])
Flips a biased coin several times and returns the associated head/tail value or array of values.

Parameters

NameTypeDescription
headObjectHead value.
tailObjectTail value.
pnumberBias (probability of head). Default is 0.5.
nnumberNumber of coins to flip. Default is 1.

Returns

objectobject[]
Single head/tail value or an array of head/tail values.

Examples

ran.core.coin('a', {b: 2})
// => { b: 2 }

ran.core.coin('a', {b: 2}, 0.9)
// => 'a'

ran.core.coin('a', {b: 2}, 0.9, 9)
// => [ { b: 2 }, 'a', 'a', 'a', 'a', 'a', 'a', { b: 2 }, 'a' ]
ran.core.float([min[, max[, n]]])
Generates some uniformly distributed random floats in (min, max). If min > max, a random float in (max, min) is generated. If no parameters are passed, generates a single random float between 0 and 1. If only min is specified, generates a single random float between 0 and min.

Parameters

NameTypeDescription
minnumberLower boundary, or upper if max is not given.
maxnumberUpper boundary.
nnumberNumber of floats to generate.

Returns

numbernumber[]
Single float or array of random floats.

Examples

ran.core.float()
// => 0.278014086611011

ran.core.float(2)
// => 1.7201255276155272

ran.core.float(2, 3)
// => 2.3693449236256185

ran.core.float(2, 3, 5)
// => [ 2.4310443387740093,
//      2.934333354639414,
//      2.7689523358767127,
//      2.291137165632517,
//      2.5040591952427906 ]
ran.core.int(min[, max[, n]])
Generates some uniformly distributed random integers in (min, max). If min > max, a random integer in (max, min) is generated. If only min is specified, generates a single random integer between 0 and min.

Parameters

NameTypeDescription
minnumberLower boundary, or upper if max is not specified.
maxnumberUpper boundary.
nnumberNumber of integers to generate.

Returns

numbernumber[]
Single integer or array of random integers.

Examples

ran.core.int(10)
// => 2

ran.core.int(10, 20)
//=> 12

ran.core.int(10, 20, 5)
// => [ 12, 13, 10, 14, 14 ]
ran.core.seed(value)
Sets the seed for the underlying pseudo random number generator used by the core generators. Under the hood, ranjs implements the xoshiro128+ algorithm as described in Blackman and Vigna: Scrambled Linear Pseudorandom Number Generators (2019).

Parameters

NameTypeDescription
valuenumberstringThe value of the seed, either a number or a string (for the ease of tracking seeds).
ran.core.shuffle(values)
Shuffles an array in-place using the Fisher‒Yates algorithm.

Parameters

NameTypeDescription
valuesArrayArray to shuffle.

Returns

Array
The shuffled array.

Examples

ran.core.shuffle([1, 2, 3])
// => [ 2, 3, 1 ]
ran.dependence.covariance(x, y)
Calculates the sample covariance for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values.

Returns

numberundefined
The sample covariance if both arrays have more than one element and they have the same length, undefined otherwise.

Examples

ran.dependence.covariance([], [])
// => undefined

ran.dependence.covariance([1], [2])
// => undefined

ran.dependence.covariance([1, 2, 3], [1, 2, 3, 4])
// => undefined

ran.dependence.covariance([1, 2, 3], [4, 5, 6])
// => 1

ran.dependence.covariance([1, 9, 10], [1, 2, 10])
// => 16.166666666666668
ran.dependence.dCor(x, y)
Calculates the distance correlation for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values.

Returns

numberundefined
The distance correlation if none of the arrays are empty and they have the same length, undefined otherwise.

Examples

ran.dependence.dCor([1, 2, 3], [])
// => undefined

ran.dependence.dCor([1, 2, 3], [2, 1, 2])
// => 0.5623413251903491
ran.dependence.dCov(x, y)
Calculates the distance covariance for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values.

Returns

numberundefined
The distance covariance if none of the arrays are empty and they have the same length, undefined otherwise.

Examples

ran.dependence.dCov([1, 2, 3], [])
// => undefined

ran.dependence.dCov([1, 2, 3], [2, 1, 2])
// => 0.31426968052735443
ran.dependence.kendall(x, y)
Calculates Kendall's rank correlation coefficient for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values.

Returns

numberundefined
Kendall's correlation coefficient if none of the arrays are empty and they have the same length, undefined otherwise.

Examples

ran.dependence.kendall([], [])
// => undefined

ran.dependence.kendall([1, 2, 3], [1, 2, 3, 4])
// => undefined

ran.dependence.kendall([1, 2, 3], [4, 5, 6])
// => 1

ran.dependence.kendall([1, 2, 3], [1, 4, 2])
// => 0.3333333333333333
ran.dependence.kullbackLeibler(p, q)
Calculates the (discrete) Kullback-Leibler divergence for two probability distributions: D_\mathrm{KL}(P \parallel Q) = \sum_{x \in \mathcal{X}} P(x) \log\bigg(\frac{P(x)}{Q(x)}\bigg).

Parameters

NameTypeDescription
pnumber[]Array representing the probabilities for the i-th value in the base distribution (P).
qnumber[]Array representing the probabilities for the i-th value in compared distribution (Q).

Returns

numberundefined
The Kullback-Leibler divergence if none of the distributions are empty and Q(x) = 0 implies that P(x) = 0 for all x, otherwise undefined.

Examples

ran.dependence.kullbackLeibler([0.1, 0.2, 0.7], [])
// => undefined

ran.dependence.kullbackLeibler([0.1, 0.2, 0.7], [0.1, 0.2, 0.3, 0.4])
// => undefined

ran.dependence.kullbackLeibler([0.1, 0.3, 0.6], [0.333, 0.333, 0.334])
// => 0.19986796234715937

ran.dependence.kullbackLeibler([0.333, 0.333, 0.334], [0.1, 0.3, 0.6])
// => 0.2396882491444514
ran.dependence.oddsRatio(p00, p01, p10, p11)
Calculates the odds ratio for the joint probabilities of two binary variables: OR(p_{00}, p_{01}, p_{10}, p_{11}) = \frac{p_{00} p_{11}}{p_{01} p_{10}}.

Parameters

NameTypeDescription
p00numberThe probability of X = 0 and Y = 0.
p01numberThe probability of X = 0 and Y = 1.
p10numberThe probability of X = 1 and Y = 0.
p11numberThe probability of X = 1 and Y = 1.

Returns

numberundefined
The odds ratio if p01 and p10 are positive, undefined otherwise.

Examples

ran.dependence.oddsRatio(0.3, 0, 0.3, 0.4)
// => undefined

ran.dependence.oddsRatio(0.3, 0.3, 0, 0.4)
// => undefined

ran.dependence.oddsRatio(0.1, 0.2, 0.3, 0.4)
// => 0.6666666666666669
ran.dependence.pearson(x, y)
Calculates the Pearson correlation coefficient for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values.

Returns

numberundefined
The Pearson correlation coefficient if none of the arrays are empty, they have the same length and each has a positive variance, undefined otherwise.

Examples

ran.dependence.pearson([], [])
// => undefined

ran.dependence.pearson([1, 2, 3], [1, 2, 3, 4])
// => undefined

ran.dependence.pearson([1, 2, 3], [1, 1, 1])
// => undefined

ran.dependence.pearson([1, 2, 3], [4, 5, 6])
// => 1

ran.dependence.pearson([1, 9, 10], [1, 2, 10])
// => 0.6643835616438358
ran.dependence.pointBiserial(x, y)
Calculates the point-biserial correlation coefficient for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values. Must contain 0s and 1s only.

Returns

numberundefined
The point-biserial correlation coefficient if none of the arrays are empty, they have the same length and each has a positive variance, undefined otherwise.

Examples

ran.dependence.pointBiserial([], [])
// => undefined

ran.dependence.pointBiserial([1, 2, 3], [0, 0, 1, 1])
// => undefined

ran.dependence.pointBiserial([2, 2, 2], [0, 0, 1])
// => undefined

ran.dependence.pointBiserial([1, 2, 3], [4, 5, 6])
// => 0.8660254037844386
ran.dependence.somersD(x, y)
Calculates Somers' D for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values.

Returns

numberundefined
Somers' D if none of the arrays are empty, they have the same length, undefined otherwise.

Examples

ran.dependence.somersD([], [])
// => undefined

ran.dependence.somersD([1, 2, 3], [1, 2, 3, 4])
// => undefined

ran.dependence.somersD([1, 2, 3], [4, 6, 6])
// => 0.6666666666666666

ran.dependence.somersD([1, 1, 0], [4, 5, 6])
// => -1
ran.dependence.spearman(x, y)
Calculates Spearman's rank correlation coefficient for two paired arrays of values.

Parameters

NameTypeDescription
xnumber[]First array of values.
ynumber[]Second array of values.

Returns

numberundefined
Spearman's rank correlation coefficient if none of the arrays are empty and they have the same length, undefined otherwise.

Examples

ran.dependence.spearman([], [])
// => undefined

ran.dependence.spearman([1, 2, 3], [1, 2, 3, 4])
// => undefined

ran.dependence.spearman([1, 2, 3], [1, 4, 2])
// => 0.5

ran.dependence.spearman([1, 9, 10], [1, 2, 10])
// => 1
ran.dependence.yuleQ(p00, p01, p10, p11)
Calculates Yule's Q for the joint probabilities of two binary variables: Q(p_{00}, p_{01}, p_{10}, p_{11}) = \frac{p_{00} p_{11} - p_{01} p_{10}}{p_{00} p_{11} + p_{01} p_{10}}.

Parameters

NameTypeDescription
p00numberThe probability of X = 0 and Y = 0.
p01numberThe probability of X = 0 and Y = 1.
p10numberThe probability of X = 1 and Y = 0.
p11numberThe probability of X = 1 and Y = 1.

Returns

numberundefined
Yule's Q if p01 and p10 are positive, undefined otherwise.

Examples

ran.dependence.yuleQ(0.3, 0, 0.3, 0.4)
// => undefined

ran.dependence.yuleQ(0.3, 0.3, 0, 0.4)
// => undefined

ran.dependence.yuleQ(0.1, 0.2, 0.3, 0.4)
// => -0.19999999999999984
ran.dependence.yuleY(p00, p01, p10, p11)
Calculates Yule's Y for the joint probabilities of two binary variables: Y(p_{00}, p_{01}, p_{10}, p_{11}) = \frac{\sqrt{p_{00} p_{11}} - \sqrt{p_{01} p_{10}}}{\sqrt{p_{00} p_{11}} + \sqrt{p_{01} p_{10}}}.

Parameters

NameTypeDescription
p00numberThe probability of X = 0 and Y = 0.
p01numberThe probability of X = 0 and Y = 1.
p10numberThe probability of X = 1 and Y = 0.
p11numberThe probability of X = 1 and Y = 1.

Returns

numberundefined
Yule's Y if p01 and p10 are positive, undefined otherwise.

Examples

ran.dependence.yuleY(0.3, 0, 0.3, 0.4)
// => undefined

ran.dependence.yuleY(0.3, 0.3, 0, 0.4)
// => undefined

ran.dependence.yuleY(0.1, 0.2, 0.3, 0.4)
// => -0.10102051443364372
ran.dispersion.cv(values)
Calculates the coefficient of variation of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate coefficient of variation for.

Returns

numberundefined
Coefficient of variation of the values if there are more than two and the mean is not zero, undefined otherwise.

Examples

ran.dispersion.cv([])
// => undefined

ran.dispersion.cv([1])
// => undefined

ran.dispersion.cv([-1, 0, 1])
// => undefined

ran.dispersion.cv([1, 2, 3, 4, 5])
// => 0.5270462766947299
ran.dispersion.dVar(x)
Calculates the distance variance for paired arrays of values.

Parameters

NameTypeDescription
xnumber[]Array of values.

Returns

numberundefined
The distance variance if the array os not empty, undefined otherwise.

Examples

ran.dependence.dVar([])
// => undefined

ran.dependence.dVar([1, 2, 3])
// => 0.7027283689263066
ran.dispersion.entropy(probabilities[, base])
Calculates the Shannon entropy for a probability distribution.

Parameters

NameTypeDescription
probabilitiesnumber[]Array representing the probabilities for the i-th value.
basenumberBase for the logarithm. If not specified, natural logarithm is used.

Returns

numberundefined
Entropy of the probabilities if there are any, undefined otherwise.

Examples

ran.dispersion.entropy([])
// => undefined

ran.dispersion.entropy([0.1, 0.1, 0.8])
// => 0.639031859650177

ran.dispersion.entropy([0.3, 0.3, 0.4])
// => 1.0888999753452238
ran.dispersion.gini(values)
Calculates the Gini coefficient for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate the Gini coefficient for.

Returns

numberundefined
The Gini coefficient of the values if there are more than one, undefined otherwise.

Examples

ran.dispersion.gini([])
// => undefined

ran.dispersion.gini([1])
// => undefined

ran.dispersion.gini([-1, 0, 1])
// => undefined

ran.dispersion.gini([1, 2, 3, 4])
// => 0.25

ran.dispersion.gini([1, 1, 1, 7])
// => 0.45
ran.dispersion.iqr(values)
Calculates the interquartile range for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate the interquartile range for.

Returns

numberundefined
The interquartile range of the values if there is any, undefined otherwise.

Examples

ran.dispersion.iqr([])
// => undefined

ran.dispersion.iqr([1, 1, 2, 3, 3])
// => 2
ran.dispersion.md(values)
Calculates the mean absolute difference of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate mean absolute difference for.

Returns

numberundefined
Mean absolute difference of the values if there are more than two, undefined otherwise.

Examples

ran.dispersion.md([])
// => undefined

ran.dispersion.md([1])
// => undefined

ran.dispersion.md([1, 2, 3, 4])
// => 1.25
ran.dispersion.midhinge(values)
Calculates the midhinge for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate midhinge for.

Returns

numberundefined
The midhinge of the values if there is any, undefined otherwise.

Examples

ran.dispersion.midhinge([])
// => undefined

ran.dispersion.midhinge([1, 1, 1, 2, 3])
// => 1.5
ran.dispersion.qcd(values)
Calculates the quartile coefficient of dispersion for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate quartile coefficient of dispersion for.

Returns

numberundefined
The quartile coefficient of dispersion of the values if there is any, undefined otherwise.

Examples

ran.dispersion.qcd([])
// => undefined

ran.dispersion.qcd([1, 2, 3])
// => 0.25
ran.dispersion.range(values)
Calculates the range for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate range for.

Returns

numberundefined
The range of the values if there is any, undefined otherwise.

Examples

ran.dispersion.range([])
// => undefined

ran.dispersion.range([0, 1, 2, 2])
// => 2
ran.dispersion.rmd(values)
Calculates the relative mean absolute difference of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate relative mean absolute difference for.

Returns

numberundefined
Relative mean absolute difference of the values if there are more than two, undefined otherwise.

Examples

ran.dispersion.rmd([])
// => undefined

ran.dispersion.rmd([1])
// => undefined

ran.dispersion.rmd([-1, 0, 1])
// => undefined

ran.dispersion.rmd([1, 2, 3, 4])
// => 0.5
ran.dispersion.stdev(values)
Calculates the unbiased standard deviation of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate standard deviation for.

Returns

numberundefined
Standard deviation of the values if there are more than two, undefined otherwise.

Examples

ran.dispersion.stdev([])
// => undefined

ran.dispersion.stdev([1])
// => undefined

ran.dispersion.stdev([1, 2, 3, 4, 5])
// => 1.5811388300841898
ran.dispersion.variance(values)
Calculates the unbiased sample variance of an array of values using Welford's algorithm.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate variance for.

Returns

numberundefined
Variance of the values if there are more than two, undefined otherwise.

Examples

ran.dispersion.variance([])
// => undefined

ran.dispersion.variance([1])
// => undefined

ran.dispersion.variance([1, 2, 3])
// => 2.5
ran.dispersion.vmr(values)
Calculates the variance-to-mean ratio of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate variance-to-mean ratio for.

Returns

numberundefined
Variance-to-mean ratio of the values if there are more than two and the mean is not zero, undefined otherwise.

Examples

ran.dispersion.vmr([])
// => undefined

ran.dispersion.vmr([1])
// => undefined

ran.dispersion.vmr([-1, 0, 1])
// => undefined

ran.dispersion.vmr([1, 2, 3, 4, 5])
// => 0.8333333333333334
ran.dist.Distribution()
The distribution generator base class, all distribution generators extend this class. The methods listed here are available for all distribution generators. Integer parameters of a distribution are rounded. The examples provided for this class are using a Pareto distribution.
ran.dist.Distribution.aic(data)
Returns the value of the Akaike information criterion for a specific data set. Note that this method does not optimize the likelihood, merely computes the AIC with the current parameter values.

Parameters

NameTypeDescription
datanumber[]Array of values containing the data.

Returns

number
The AIC for the current parameters.

Examples

let pareto1 = new dist.Pareto(1, 2)
let pareto2 = new dist.Pareto(1, 5)
let sample = pareto1.sample(1000)

pareto1.aic(sample)
// => 1584.6619128383577

pareto2.aic(sample)
// => 2719.0367230482957
ran.dist.Distribution.bic(data)
Returns the value of the Bayesian information criterion for a specific data set. Note that this method does not optimize the likelihood, merely computes the BIC with the current parameter values.

Parameters

NameTypeDescription
datanumber[]Array of values containing the data.

Returns

number
The BIC for the current parameters.

Examples

let pareto1 = new dist.Pareto(1, 2)
let pareto2 = new dist.Pareto(1, 5)
let sample = pareto1.sample(1000)

pareto1.bic(sample)
// => 1825.3432698372499

pareto2.bic(sample)
// => 3190.5839264881165
ran.dist.Distribution.cdf(x)
The cumulative distribution function: F(x) = \int_{-\infty}^x f(t) ,\mathrm{d}t, if the distribution is continuous and F(x) = \sum_{x_i \le x} f(x_i), if it is discrete. The functions f(t) and f(x_i) denote the probability density and mass functions.

Parameters

NameTypeDescription
xnumberValue to evaluate CDF at.

Returns

number
The cumulative distribution value.

Examples

let pareto = new ran.dist.Pareto(1, 2)
pareto.cdf(3)
// => 0.8888888888888888
ran.dist.Distribution.cHazard(x)
The cumulative hazard function: \Lambda(x) = \int_0^x \lambda(t) ,\mathrm{d}t, where \lambda(x) is the hazard function.

Parameters

NameTypeDescription
xnumberValue to evaluate cumulative hazard at.

Returns

number
The cumulative hazard.

Examples

let pareto = new ran.dist.Pareto(1, 2)
pareto.cHazard(3)
// => 2.197224577336219
ran.dist.Distribution.hazard(x)
The hazard function: \lambda(x) = \frac{f(x)}{S(x)}, where f(x) and S(x) are the probability density (or mass) function and the survival function, respectively.

Parameters

NameTypeDescription
xnumberValue to evaluate the hazard at.

Returns

number
The hazard value.

Examples

let pareto = new ran.dist.Pareto(1, 2)
pareto.hazard(3)
// => 0.6666666666666663
ran.dist.Distribution.lnL(data)
The log-likelihood of the current distribution based on some data. More precisely: \ln L(\theta | X) = \sum_{x \in X} \ln f(x; \theta), where X is the set of observations (sample) and \theta is the parameter vector of the distribution. The function f(x) denotes the probability density/mass function.

Parameters

NameTypeDescription
datanumber[]Array of numbers to calculate log-likelihood for.

Returns

number
The log-likelihood of the data for the distribution.

Examples

let pareto = new ran.dist.Pareto(1, 2)
let uniform = new ran.dist.UniformContinuous(1, 10);

let sample1 = pareto.sample(100)
pareto.L(sample1)
// => -104.55926409382

let sample2 = uniform.sample(100)
pareto.L(sample2)
// => -393.1174868780569
ran.dist.Distribution.load(state)
Loads a new state for the generator.

Parameters

NameTypeDescription
stateObjectThe state to load.

Returns

ran.dist.Distribution
Reference to the current distribution.

Examples

let pareto1 = new ran.dist.Pareto(1, 2).seed('test')
let sample1 = pareto1.sample(2)
let state = pareto1.save()

let pareto2 = new ran.dist.Pareto().load(state)
let sample2 = pareto2.sample(3)
// => [ 1.1315154468682591,
//      5.44269493220745,
//      1.2587482868229616 ]
ran.dist.Distribution.logPdf(x)
The logarithmic probability density function. For discrete distributions, this is the logarithm of the probability mass function.

Parameters

NameTypeDescription
xnumberValue to evaluate the log pdf at.

Returns

number
The logarithmic probability density (or mass).

Examples

let pareto = new ran.dist.Pareto(1, 2)
pareto.lnPdf(3)
// => -2.6026896854443837
ran.dist.Distribution.pdf(x)
Probability density function. In case of discrete distributions, it is the probability mass function.

Parameters

NameTypeDescription
xnumberValue to evaluate distribution at.

Returns

number
The probability density or probability mass.

Examples

let pareto = new ran.dist.Pareto(1, 2)
pareto.pdf(3)
// => 0.07407407407407407
ran.dist.Distribution.q(p)
The quantile function of the distribution. For continuous distributions, it is defined as the inverse of the distribution function: Q(p) = F^{-1}(p), whereas for discrete distributions it is the lower boundary of the interval that satisfies F(k) = p : Q(p) = \mathrm{inf}\{k \in \mathrm{supp}(f): p \le F(k)\}, with \mathrm{supp}(f) denoting the support of the distribution. For distributions with an analytically invertible cumulative distribution function, the quantile is explicitly implemented. In other cases, two fallback estimations are used: for continuous distributions the equation F(x) = p is solved using Brent's method. For discrete distributions a look-up table is used with linear search.

Parameters

NameTypeDescription
pnumberThe probability at which the quantile should be evaluated.

Returns

numberundefined
The value of the quantile function at the specified probability if p \in [0, 1] and the quantile could be found, undefined otherwise.
ran.dist.Distribution.sample([n])
Generates some random variate.

Parameters

NameTypeDescription
nnumberNumber of variates to generate. If not specified, a single value is returned.

Returns

numbernumber[]
Single sample or an array of samples.

Examples

let pareto = new ran.dist.Pareto(1, 2)
pareto.sample(5)
// => [ 5.619011325146519,
//      1.3142187491180493,
//      1.0513159445581859,
//      1.8124951360943067,
//      1.1694087449301402 ]
ran.dist.Distribution.save()
Returns the current state of the generator. The object returned by this method contains all information necessary to set up another generator of the same distribution (parameters, state of the pseudo random generator, etc).

Returns

Object
Object representing the inner state of the current generator.

Examples

let pareto1 = new ran.dist.Pareto(1, 2).seed('test')
let sample1 = pareto1.sample(2)
let state = pareto1.save()

let pareto2 = new ran.dist.Pareto().load(state)
let sample2 = pareto2.sample(3)
// => [ 1.1315154468682591,
//      5.44269493220745,
//      1.2587482868229616 ]
ran.dist.Distribution.seed(value)
Sets the seed for the distribution generator. Distributions implement the same PRNG ( xoshiro128+) that is used in the core functions.

Parameters

NameTypeDescription
valuenumberstringThe value of the seed, either a number or a string (for the ease of tracking seeds).

Returns

ran.dist.Distribution
Reference to the current distribution.

Examples

let pareto = new ran.dist.Pareto(1, 2).seed('test')
pareto.sample(5)
// => [ 1.571395735462202,
//      2.317583041477979,
//      1.1315154468682591,
//      5.44269493220745,
//      1.2587482868229616 ]
ran.dist.Distribution.support()
Returns the support of the probability distribution (based on the current parameters). Note that the support for the probability distribution is not necessarily the same as the support of the cumulative distribution.

Returns

Object[]
An array of objects describing the lower and upper boundary of the support. Each object contains a value: number and a closed: boolean property with the value of the boundary and whether it is closed, respectively. When value is (+/-)Infinity, closed is always false.
ran.dist.Distribution.survival(x)
The survival function: S(x) = 1 - F(x), where F(x) denotes the cumulative distribution function.

Parameters

NameTypeDescription
xnumberValue to evaluate survival function at.

Returns

number
The survival value.

Examples

let pareto = new ran.dist.Pareto(1, 2)
pareto.survival(3)
// => 0.11111111111111116
ran.dist.Distribution.test(values)
Tests if an array of values is sampled from the specified distribution. For discrete distributions this method uses \chi^2 test, whereas for continuous distributions it uses the Kolmogorov-Smirnov test. In both cases, the probability of Type I error (rejecting a correct null hypotheses) is 1%.

Parameters

NameTypeDescription
valuesnumber[]Array of values to test.

Returns

Object
Object with two properties representing the result of the test:
  • {statistics}: The \chi^2 or D statistics depending on whether the distribution is discrete or continuous.
  • {passed}: Whether the sample passed the null hypothesis that it is sampled from the current distribution.

Examples

let pareto = new ran.dist.Pareto(1, 2)
let uniform = new ran.dist.UniformContinuous(1, 10);

let sample1 = pareto.sample(100)
pareto.test(sample1)
// => { statistics: 0.08632443341496943, passed: true }

let sample2 = uniform.sample(100)
pareto.test(sample2)
// => { statistics: 0.632890888159255, passed: false }
ran.dist.Distribution.type()
Returns the type of the distribution (either discrete or continuous).

Returns

string
Distribution type.
ran.dist.Alpha([alpha[, beta]])
Generator for the alpha distribution: f(x; \alpha, \beta) = \frac{\phi\Big(\alpha - \frac{\beta}{x}\Big)}{x^2 \Phi(\alpha)}, where \alpha, \beta > 0 and \phi(x), \Phi(x) denote the probability density and cumulative probability functions of the normal distribution. Support: x > 0 .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 1.
betanumberScale parameter. Default value is 1.
ran.dist.Anglit([mu[, beta]])
Generator for the anglit distribution: f(x; \mu, \beta) = \frac{1}{\beta} \cos\bigg(2 \frac{x - \mu}{\beta}\bigg), where \mu \in \mathbb{R} and \beta > 0 . Support: x \in \Big[\mu-\frac{\beta \pi}{4}, \mu + \frac{\beta \pi}{4}\Big] .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
betanumberScale parameter. Default value is 1.
ran.dist.Arcsine([a[, b]])
Generator for the arbitrarily bounded arcsine distribution: f(x; a, b) = \frac{1}{\pi \sqrt{(x -a) (b - x)}}, where a, b \in \mathbb{R} and a < b . Support: x \in [a, b] .

Parameters

NameTypeDescription
anumberLower boundary. Default value is 0.
bnumberUpper boundary. Default value is 1.
ran.dist.BaldingNichols([F[, p]])
Generator for the Balding-Nichols distribution: f(x; \alpha, \beta) = \frac{x^{\alpha - 1} (1 - x)^{\beta - 1}}{\mathrm{B}(\alpha, \beta)}, where \alpha = \frac{1 - F}{F} p , \beta = \frac{1 - F}{F} (1 - p) and F, p \in (0, 1) . Support: x \in (0, 1) . It is simply a re-parametrization of the beta distribution.

Parameters

NameTypeDescription
FnumberFixation index. Default value is 0.5.
pnumberAllele frequency. Default value is 0.5.
ran.dist.Bates([n[, a[, b]]])
Generator for the Bates distribution: f(x; n, a, b) = \frac{n}{(b - a)(n - 1)!} \sum_{k = 0}^{\lfloor nz \rfloor} (-1)^k \begin{pmatrix}n \\ k \\ \end{pmatrix} (nz - k)^{n - 1}, with z = \frac{x - a}{b - a} , n \in \mathbb{N}^+ and a, b \in \mathbb{R}, a < b . Support: x \in [a, b] .

Parameters

NameTypeDescription
nnumberNumber of uniform variates to sum. If not an integer, it is rounded to the nearest one. Default value is 10.
anumberLower boundary of the uniform variate. Default value is 0.
bnumberUpper boundary of the uniform variate. Default value is 1.
ran.dist.Benini([alpha[, beta[, sigma]]])
Generator for the Benini distribution: f(x; \alpha, \beta, \sigma) = \bigg(\frac{\alpha}{x} + \frac{2 \beta \ln \frac{x}{\sigma}}{x}\bigg) e^{-\alpha \ln \frac{x}{\sigma} - \beta \ln^2 \frac{x}{\sigma}}, with \alpha, \beta, \sigma > 0 . Support: x \in (\sigma, \infty) .

Parameters

NameTypeDescription
alphanumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 1.
sigmanumberScale parameter. Default value is 1.
ran.dist.BenktanderII([a[, b]])
Generator for the Benktander type II distribution: f(x; a, b) = e^{\frac{a}{b}(1 - x^b)} x^{b-2} (ax^b - b + 1), with a > 0 and b \in (0, 1] . Support: x \in [1, \infty) .

Parameters

NameTypeDescription
anumberScale parameter. Default value is 1.
bnumberShape parameter. Default value is 0.5.
ran.dist.Bernoulli([p])
Generator for the Bernoulli distribution: f(k; p) = \begin{cases}p &\quad\text{if $k = 1$},\\1 - p &\quad\text{if $k = 0$},\\\end{cases}, where p \in [0, 1] . Support: k \in \{0, 1\} .

Parameters

NameTypeDescription
pnumberProbability of the outcome 1. Default value is 0.5.
ran.dist.Beta([alpha[, beta]])
Generator for the beta distribution: f(x; \alpha, \beta) = \frac{x^{\alpha - 1}(1 - x)^{\beta - 1}}{\mathrm{B}(\alpha, \beta)}, with \alpha, \beta > 0 and \mathrm{B}(\alpha, \beta) is the beta function. Support: x \in (0, 1) .

Parameters

NameTypeDescription
alphanumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 1.
ran.dist.BetaBinomial([n[, alpha[, beta]]])
Generator for the beta-binomial distribution: f(k; n, \alpha, \beta) = \begin{pmatrix}n \\ k \\ \end{pmatrix} \frac{\mathrm{B}(\alpha + k, \beta + n - k)}{\mathrm{B}(\alpha, \beta)}, with n \in \mathbb{N}_0 and \alpha, \beta > 0 . Support: k \in {0, ..., n} .

Parameters

NameTypeDescription
nnumberNumber of trials. Default value is 10.
alphanumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 2.
ran.dist.BetaPrime([alpha[, beta]])
Generator for the beta prime distribution (also known as inverted beta): f(x; \alpha, \beta) = \frac{x^{\alpha - 1}(1 + x)^{-\alpha - \beta}}{\mathrm{B}(\alpha, \beta)}, with \alpha, \beta > 0 and \mathrm{B}(x, y) is the beta function. Support: x > 0 .

Parameters

NameTypeDescription
alphanumberFirst shape parameter. Default value is 2.
betanumberSecond shape parameter. Default value is 2.
ran.dist.BetaRectangular([alpha[, beta[, theta[, a[, b]]]]])
Generator for the beta-rectangular distribution: f(x; \alpha, \beta, \theta, a, b) = \theta \frac{(x - a)^{\alpha - 1} (b - x)^{\beta - 1}}{\mathrm{B}(\alpha, \beta) (b - a)^{\alpha + \beta - 1}} + \frac{1 - \theta}{b - a}, with \alpha, \beta > 0 , \theta \in [0, 1] , a, b \in \mathbb{R} , a < b and \mathrm{B}(x, y) is the beta function. Support: x \in [a, b] .

Parameters

NameTypeDescription
alphanumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 1.
thetanumberMixture parameter. Default value is 0.5.
anumberLower boundary of the support. Default value is 0.
bnumberUpper boundary of the support. Default value is 1.
ran.dist.Binomial([n[, p]])
Generator for the binomial distribution: f(k; n, p) = \begin{pmatrix}n \\ k \\ \end{pmatrix} p^k (1 - p)^{n - k}, with n \in \mathbb{N}_0 and p \in [0, 1] . Support: k \in {0, ..., n} .

Parameters

NameTypeDescription
nnumberNumber of trials. Default value is 100.
pnumberProbability of success. Default value is 0.5.
ran.dist.BirnbaumSaunders([mu[, beta[, gamma]]])
Generator for the Birnbaum-Saunders distribution (also known as fatigue life distribution): f(x; \mu, \beta, \gamma) = \frac{z + 1 / z}{2 \gamma (x - \mu)} \phi\Big(\frac{z - 1 / z}{\gamma}\Big), with \mu \in \mathbb{R} , \beta, \gamma > 0 , z = \sqrt{\frac{x - \mu}{\beta}} and \phi(x) is the probability density function of the standard normal distribution. Support: x \in (\mu, \infty) .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
betanumberScale parameter. Default value is 1.
gammanumberShape parameter. Default value is 1.
ran.dist.Borel(mu)
Generator for the Borel distribution: f(k; \mu) = \frac{e^{-\mu k} (\mu k)^{k - 1}}{k!}, where \mu \in [0, 1] . Support: k \in \mathbb{N}^+ .

Parameters

NameTypeDescription
munumberDistribution parameter. Default value is 0.5.
ran.dist.BorelTanner(mu, n)
Generator for the Borel-Tanner distribution: f(k; \mu, n) = \frac{n}{k}\frac{e^{-\mu k} (\mu k)^{k - n}}{(k - n)!}, where \mu \in [0, 1] and n \in \mathbb{N}^+ . Support: k \ge n .

Parameters

NameTypeDescription
munumberDistribution parameter. Default value is 0.5.
nnumberNumber of Borel distributed variates to add. If not an integer, it is rounded to the nearest one. Default value is 2.
ran.dist.BoundedPareto([L[, H[, alpha]]])
Generator for the bounded Pareto distribution: f(x; L, H, \alpha) = \frac{\alpha L^\alpha x^{-\alpha - 1}}{1 - \big(\frac{L}{H}\big)^\alpha}, with L, H > 0 , H > L and \alpha > 0 . Support: x \in [L, H] .

Parameters

NameTypeDescription
LnumberLower boundary. Default value is 1.
HnumberUpper boundary. Default value is 10.
alphanumberShape parameter. Default value is 1.
ran.dist.Bradford([c])
Generator for the Bradford distribution: f(x; c) = \frac{c}{\ln(1 + c) (1 + c x)}, with c > 0 . Support: x \in [0, 1] .

Parameters

NameTypeDescription
cnumberShape parameter. Default value is 1.
ran.dist.Burr([c[, k]])
Generator for the Burr (XII) distribution (also known as Singh-Maddala distribution): f(x; c, k) = c k \frac{x^{c - 1}}{(1 + x^c)^{k + 1}}, with c, k > 0 . Support: x > 0 .

Parameters

NameTypeDescription
cnumberFirst shape parameter. Default value is 1.
knumberSecond shape parameter. Default value is 1.
ran.dist.Categorical([weights[, min]])
Generator for a categorical distribution: f(k; {w}) = \frac{w_k}{\sum_j w_j}, where w_k > 0 . Support: k \in \mathbb{N}_0 .

Parameters

NameTypeDescription
weightsnumber[]Weights for the distribution (doesn't need to be normalized). Default value is an array with a single value of 1.
minnumberLowest value to sample (support starts at this value). Default value is [1, 1, 1].
ran.dist.Cauchy([x0[, gamma]])
Generator for the Cauchy distribution: f(x; x_0, \gamma) = \frac{1}{\pi\gamma\bigg[1 + \Big(\frac{x - x_0}{\gamma}\Big)^2\bigg]} where x_0 \in \mathbb{R} and \gamma > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
x0numberLocation parameter. Default value is 0.
gammanumberScale parameter. Default value is 1.
ran.dist.Chi([k])
Generator for the \chi distribution: f(x; k) = \frac{1}{2^{k/2 - 1} \Gamma(k/2)} x^{k - 1} e^{-x^2/2}, where k \in \mathbb{N}^+ . Support: x > 0 .

Parameters

NameTypeDescription
knumberDegrees of freedom. If not an integer, is rounded to the nearest integer. Default value is 2.
ran.dist.Chi2([k])
Generator for the \chi^2 distribution: f(x; k) = \frac{1}{2^{k/2} \Gamma(k/2)} x^{k/2 - 1} e^{-x/2}, where k \in \mathbb{N}^+ . Support: x > 0 .

Parameters

NameTypeDescription
knumberDegrees of freedom. If not an integer, is rounded to the nearest one. Default value is 2.
ran.dist.Dagum([p[, a[, b]]])
Generator for the Dagum distribution: f(x; p, a, b) = \frac{ap}{x} \frac{\big(\frac{x}{b}\big)^{ap}}{\Big[\big(\frac{x}{b}\big)^a + 1\Big]^{p + 1}}, with p, a, b > 0 . Support: x > 0 .

Parameters

NameTypeDescription
pnumberFirst shape parameter. Default value is 1.
anumberSecond shape parameter. Default value is 1.
bnumberScale parameter. Default value is 1.
ran.dist.Degenerate([x0])
Generator for the degenerate distribution: f(x; x_0) = \begin{cases}1 &\quad\text{if $x = x_0$}\\0 &\quad\text{otherwise}\\\end{cases}, where x_0 \in \mathbb{R} . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
x0numberLocation of the distribution. Default value is 0.
ran.dist.Delaporte([alpha[, beta[, lambda]]])
Generator for the Delaporte distribution: f(k; \alpha, \beta, \lambda) = \frac{e^{-\lambda}}{\Gamma(\alpha)}\sum_{j = 0}^k \frac{\Gamma(\alpha + j) \beta^j \lambda^{k - j}}{j! (1 + \beta)^{\alpha + j} (k - j)!}, with \alpha, \beta, \lambda > 0 . Support: k \in \mathbb{N}_0 . For \lambda = 0 , it is the negative binomial, and for \alpha = \beta = 0 it is the [Poisson distribution]#dist.Poisson. Note that these special cases are not covered by this class. For these distributions, please refer to the corresponding generators.

Parameters

NameTypeDescription
alphanumberShape parameter of the gamma component. Default component is 1.
betanumberScale parameter of the gamma component. Default value is 1.
lambdanumberMean of the Poisson component. Default value is 1.
ran.dist.DiscreteUniform([xmin[, xmax]])
Generator for the discrete uniform distribution: f(k; x_\mathrm{min}, x_\mathrm{max}) = \frac{1}{x_\mathrm{max} - x_\mathrm{min} + 1}, with x_\mathrm{min}, x_\mathrm{max} \in \mathbb{Z} and x_\mathrm{min} < x_\mathrm{max} . Support: k \in {x_\mathrm{min}, ..., x_\mathrm{max}} .

Parameters

NameTypeDescription
xminnumberLower boundary. If not an integer, it is rounded to the nearest one. Default value is 0.
xmaxnumberUpper boundary. If not an integer, it is rounded to the nearest one. Default value is 100.
ran.dist.DiscreteWeibull([q[, beta]])
Generator for the discrete Weibull distribution (using the original parametrization): f(k; q, \beta) = q^{k^\beta} - q^{(k + 1)^\beta}, with q \in (0, 1) and \beta > 0 . Support: k \in \mathbb{N}_0 .

Parameters

NameTypeDescription
qnumberFirst shape parameter. Default value is 0.5.
betanumberSecond shape parameter. Default value is 1.
ran.dist.DoubleGamma([alpha[, beta]])
Generator for the double gamma distribution (with the same shape/rate parametrization that the [gamma distribution]#dist.Gamma uses): f(x; \alpha, \beta) = \frac{\beta^\alpha}{2 \Gamma(\alpha)} |x|^{\alpha - 1} e^{-\beta |x|}, where \alpha, \beta > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 1.
betanumberRate parameter. Default value is 1.
ran.dist.DoubleWeibull([lambda[, k]])
Generator for the double Weibull distribution: f(x; \lambda, k) = \frac{k}{\lambda}\bigg(\frac{|x|}{\lambda}\bigg)^{k - 1} e^{-(|x| / \lambda)^k}, with \lambda, k > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
lambdanumberScale parameter. Default value is 1.
knumberShape parameter. Default value is 1.
ran.dist.DoublyNoncentralBeta([alpha[, beta[, lambda1[, lambda2]]]])
Generator for the doubly non-central beta distribution: f(x; \alpha, \beta, \lambda_1, \lambda_2) = e^{-\frac{\lambda_1 + \lambda_2}{2}} \sum_{k = 0}^\infty \sum_{l = 0}^\infty \frac{\big(\frac{\lambda_1}{2}\big)^k}{k!} \frac{\big(\frac{\lambda_2}{2}\big)^l}{l!} \frac{x^{\alpha + k - 1} (1 - x)^{\beta + l - 1}}{\mathrm{B}\big(\alpha + k, \beta + l\big)}, where \alpha, \beta > 0 and \lambda_1, \lambda_2 \ge 0 . Support: x \in (0, 1) .

Parameters

NameTypeDescription
alphanumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 1.
lambda1numberFirst non-centrality parameter. Default value is 1.
lambda2numberSecond non-centrality parameter. Default value is 1.
ran.dist.DoublyNoncentralF([d1[, d2[, lambda1[, lambda2]]]])
Generator for the doubly non-central F distribution: f(x; d_1, d_2, \lambda_1, \lambda_2) = \frac{d_1}{d_2} e^{-\frac{\lambda_1 + \lambda_2}{2}} \sum_{k = 0}^\infty \sum_{l = 0}^\infty \frac{\big(\frac{\lambda_1}{2}\big)^k}{k!} \frac{\big(\frac{\lambda_2}{2}\big)^l}{l!} \frac{\big(\frac{d_1 x}{d_2}\big)^{\frac{d_1}{2} + k - 1}}{\big(1 + \frac{d_1 x}{d_2}\big)^{\frac{d_1 + d_2}{2} + k + l}} \frac{1}{\mathrm{B}\big(\frac{d_1}{2} + k, \frac{d_2}{2} + l\big)}, where d_1, d_2 \in \mathbb{N}^+ and \lambda_1, \lambda_2 \ge 0 . Support: x > 0 .

Parameters

NameTypeDescription
d1numberFirst degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
d2numberSecond degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
lambda1numberFirst non-centrality parameter. Default value is 1.
lambda2numberSecond non-centrality parameter. Default value is 1.
ran.dist.DoublyNoncentralT(nu, mu, theta)
Generator for the doubly non-central t distribution: f(x; \nu, \mu, \theta) = \frac{e^{-\frac{\theta + \mu^2}{2}}}{\sqrt{\pi \nu}} \sum_{j = 0}^\infty \frac{1}{j!} \frac{(x \mu \sqrt{2 / \nu})^j}{(1 + x^2 / \nu)^{\frac{\nu + j + 1}{2}}} \frac{\Gamma\big(\frac{\nu + j + 1}{2}\big)}{\Gamma\big(\frac{\nu}{2}\big)} {}_1F_1\bigg(\frac{\nu + j + 1}{2}, \frac{\nu}{2}; \frac{\theta}{2 (1 + x^2 / \nu)}\bigg), where \nu \in \mathbb{N}^+ , \mu \in \mathbb{R} and \theta > 0 . Support: x \in \mathbb{R} . Implementation is based on Section 10.4.1.2 in Marc S. Paolella. Intermediate Probability: A Computational Approach. (2007)

Parameters

NameTypeDescription
nunumberDegrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 1.
munumberLocation parameter. Default value is 1.
thetanumberShape parameter. Default value is 1.
ran.dist.Erlang([k[, lambda]])
Generator for the Erlang distribution: f(x; k, \lambda) = \frac{\lambda^k x^{k - 1} e^{-\lambda x}}{(k - 1)!}, where k \in \mathbb{N}^+ and \lambda > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
knumberShape parameter. It is rounded to the nearest integer. Default value is 1.
lambdanumberRate parameter. Default value is 1.
ran.dist.Exponential([lambda])
Generator for the exponential distribution: f(x; \lambda) = \lambda e^{-\lambda x}, with \lambda > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
lambdanumberRate parameter. Default value is 1.
ran.dist.ExponentialLogarithmic([p[, beta]])
Generator for the exponential-logarithmic distribution: f(x; p, \beta) = -\frac{1}{\ln p} \frac{\beta (1 - p) e^{-\beta x}}{1 - (1 - p) e^{-\beta x}}, with p \in (0, 1) and \beta > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
pnumberShape parameter. Default value is 0.5.
betanumberScale parameter. Default value is 1.
ran.dist.ExponentiatedWeibull([lambda[, k[, alpha]]])
Generator for the exponentiated Weibull distribution: f(x; \lambda, k) = \alpha \frac{k}{\lambda}\bigg(\frac{x}{\lambda}\bigg)^{k - 1} \bigg[1 - e^{-(x / \lambda)^k}\bigg]^{\alpha - 1} e^{-(x / \lambda)^k}, with \lambda, k, \alpha > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
lambdanumberScale parameter. Default value is 1.
knumberFirst shape parameter. Default value is 1.
alphanumberSecond shape parameter. Default value is 1.
ran.dist.F([d1[, d2]])
Generator for the F distribution (or Fisher-Snedecor's F distribution): f(x; d_1, d_2) = \frac{\sqrt{\frac{(d_1 x)^{d_1} d_2^{d_2}}{(d_1x + d_2)^{d_1 + d_2}}}}{x \mathrm{B}\big(\frac{d_1}{2}, \frac{d_2}{2}\big)}, with d_1, d_2 > 0 . Support: x > 0 .

Parameters

NameTypeDescription
d1numberFirst degree of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
d2numberSecond degree of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
ran.dist.FisherZ([d1[, d2]])
Generator for Fisher's z distribution: f(x; d_1, d_2) = \sqrt{\frac{d_1^{d_1} d_2^{d_2}}{(d_1 e^{2 x} + d_2)^{d_1 + d_2}}} \frac{2 e^{d_1 x}}{\mathrm{B}\big(\frac{d_1}{2}, \frac{d_2}{2}\big)}, with d_1, d_2 > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
d1numberFirst degree of freedom. Default value is 2.
d2numberSecond degree of freedom. Default value is 2.
ran.dist.FlorySchulz([a])
Generator for the Flory-Schulz distribution: f(k; a) = a^2 k (1 - a)^{k - 1}, with a \in (0, 1) . Support: k \in \mathbb{N}^+ .

Parameters

NameTypeDescription
anumberShape parameter. Default value is 0.5.
ran.dist.Frechet([alpha[, s[, m]]])
Generator for the Frechet distribution: f(x; \alpha, s, m) = \frac{\alpha z^{-1 -\alpha} e^{-z^{-\alpha}}}{s}, with z = \frac{x - m}{s} . and \alpha, s > 0 , m \in \mathbb{R} . Support: x \in \mathbb{R}, x > m .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 1.
snumberScale parameter. Default value is 1.
mnumberLocation parameter. Default value is 0.
ran.dist.Gamma([alpha[, beta]])
Generator for the gamma distribution using the shape/rate parametrization: f(x; \alpha, \beta) = \frac{\beta^\alpha}{\Gamma(\alpha)} x^{\alpha - 1} e^{-\beta x}, where \alpha, \beta > 0 . Support: x > 0 .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 1.
betanumberRate parameter. Default value is 1.
ran.dist.GammaGompertz([b[, s[, beta]]])
Generator for the Gamma/Gompertz distribution: f(x; b, s, \beta) = \frac{b s e^{b x} \beta^s}{(\beta - 1 + e^{b x})^{s + 1}}, with b, s, \beta > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
bnumberScale parameter. Default value is 1.
snumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 1.
ran.dist.GeneralizedExponential([a[, b[, c]]])
Generator for the generalized exponential distribution: f(x; a, b, c) = \big(a + b (1 - e^{-c x})\big) e^{-(a + b)x + \frac{b}{c} (1 - e^{-c x})}, where a, b, c > 0 . Support> x \ge 0 .

Parameters

NameTypeDescription
anumberFirst shape parameter. Default value is 1.
bnumberSecond shape parameter. Default value is 1.
cnumberThird shape parameter. Default value is 1.
ran.dist.GeneralizedExtremeValue([c])
Generator for the generalized extreme value distribution: f(x; c) = (1 - cx)^{1 / c - 1} e^{-(1 - cx)^{1 / c}}, with c \ne 0 . Support: x \in (-\infty, 1 / c] if c > 0 , x \in [1 / c, \infty) otherwise.

Parameters

NameTypeDescription
cnumberShape parameter. Default value is 2.
ran.dist.GeneralizedGamma([a[, d[, p]]])
Generator for the generalized gamma distribution: f(x; a, d, p) = \frac{p/a^d}{\Gamma(d/p)} x^{d - 1} e^{-(x/a)^p}, where a, d, p > 0 . Support: x > 0 .

Parameters

NameTypeDescription
anumberScale parameter. Default value is 1.
dnumberShape parameter. Default value is 1.
pnumberShape parameter. Default value is 1.
ran.dist.GeneralizedHermite([a1[, am[, m]]])
Generator for the generalized Hermite distribution: f(k; a_1, a_m, m) = p_0 \frac{\mu^k (m - d)^k}{(m - 1)^k} \sum_{j = 0}^{\lfloor k / m \rfloor} \frac{(d - 1)^j (m - 1)^{(m - 1)j}}{m^j \mu^{(m - 1)j} (m - d)^{mj} (k - mj)! j!}, where p_0 = e^{\mu \big[\frac{d - 1}{m} - 1\big]} , \mu = a_1 + m a_m , d = \frac{a_1 + m^2 a_m}{a_1 + m a_m} , a_1, a_m > 0 and m \in \mathbb{N}^+ \setminus { 1 } . Support: k \in \mathbb{N} . It is the distribution of X_1 + m X_m where X_1, X_2 are Poisson variates with parameters a_1, a_m respectively.

Parameters

NameTypeDescription
a1numberMean of the first Poisson component. Default value is 1.
amnumberMean of the second Poisson component. Default value is 1.
mnumberMultiplier of the second Poisson. If not an integer, it is rounded to the nearest one. Default value is 2.
ran.dist.GeneralizedLogistic([mu[, s[, c]]])
Generator for the generalized logistic distribution: f(x; \mu, s, c) = \frac{c e^{-z}}{s (1 + e^{-z})^{c + 1}}, with z = \frac{x - \mu}{s} , \mu \in \mathbb{R} and s, c > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
snumberScale parameter. Default value is 1.
cnumberShape parameter. Default value is 1.
ran.dist.GeneralizedNormal([mu[, alpha[, beta]]])
Generator for the generalized normal distribution: f(x; \mu, \alpha, \beta) = \frac{\beta}{2 \alpha \Gamma\big(\frac{1}{\beta}\big)} e^{-\big(\frac{|x - \mu|}{\alpha}\big)^\beta}, where \mu \in \mathbb{R} and \alpha, \beta > 0 . Support: x \in \mathbb{R} . It is also a special case of the generalized gamma distribution.

Parameters

NameTypeDescription
munumberLocation paramameter. Default value is 0.
alphanumberScale parameter. Default value is 1.
betanumberShape parameter. Default value is 1.
ran.dist.GeneralizedPareto([mu[, sigma[, xi]]])
Generator for the generalized Pareto distribution: f(x; \mu, \sigma, \xi) = \begin{cases}\frac{1}{\sigma} (1 + \xi z)^{-(1/\xi + 1)} &\quad\text{if $\xi \ne 0$},\\\frac{1}{\sigma} e^{-z} &\quad\text{if $\xi = 0$}\\\end{cases}, with \mu, \xi \in \mathbb{R} , \sigma > 0 and z = \frac{x - \mu}{\sigma} . Support: x \in [\mu, \infty) if \xi \ge 0 , x \in [\mu, \mu - \sigma / \xi] otherwise.

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
sigmanumberScale parameter. Default value is 1.
xinumberShape parameter. Default value is 1.
ran.dist.Geometric(p)
Generator for the geometric distribution (the number of failures before the first success definition): f(k; p) = p (1 - p)^k, with p \in (0, 1] . Support: k \in {0, 1, 2, ...} . Note that the discrete exponential distribution is also a geometric distribution with rate parameter equal to -\ln(1 - p) .

Parameters

NameTypeDescription
pnumberProbability of success. Default value is 0.5.
ran.dist.Gilbrat()
Generator for the Gilbrat's distribution: f(x) = \frac{1}{x \sqrt{2 \pi}}e^{-\frac{\ln x^2}{2}}. Support: x > 0 . Note that this distribution is simply a special case of the log-normal.
ran.dist.Gompertz([eta[, beta]])
Generator for the Gompertz distribution: f(x; \eta, b) = b \eta e^{\eta + bx - \eta e^{bx}} , with \eta, b > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
etanumberShape parameter. Default value is 1.
betanumberScale parameter. Default value is 1.
ran.dist.Gumbel([mu[, beta]])
Generator for the Gumbel distribution: f(x; \mu, \beta) = \frac{1}{\beta} e^{-(z + e^{-z})}, with z = \frac{x - \mu}{\beta} and \mu \in \mathbb{R} , \beta > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
betanumberScale parameter. Default value is 1.
ran.dist.HalfGeneralizedNormal([alpha[, beta]])
Generator for the half generalized normal distribution: f(x; \alpha, \beta) = \frac{\beta}{\Gamma\big(\frac{1}{\beta}\big)} e^{-|x|^\beta}, with \alpha, \beta > 0 . Support: x > 0 .

Parameters

NameTypeDescription
alphanumberScale parameter. Default value is 1.
betanumberShape parameter. Default value is 1.
ran.dist.HalfLogistic()
Generator for the half-logistic distribution: f(x) = \frac{2 e^{-x}}{(1 + e^{-x})^2}. Support: x \in [0, \infty) .
ran.dist.HalfNormal([sigma])
Generator for the half-normal distribution: f(x; \sigma) = \frac{\sqrt{2}}{\sigma\sqrt{\pi}} e^{-\frac{x^2}{2\sigma^2}}, with \sigma > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
sigmanumberScale parameter. Default value is 1.
ran.dist.HeadsMinusTails([n])
Generator for the heads-minus-tails distribution: f(k; n) = \begin{cases}\Big(\frac{1}{2}\Big)^{2n} \begin{pmatrix}2n \\ n \\ \end{pmatrix} &\quad\text{if $k = 0$},\\2 \Big(\frac{1}{2}\Big)^{2n} \begin{pmatrix}2n \\ m + n \\ \end{pmatrix} &\quad\text{if $k = 2m$},\\0 &\quad\text{else}\\ \end{cases} where n \in \mathbb{N}^+ . Support: k \in [0, n] .

Parameters

NameTypeDescription
nnumberHalf number of trials. Default value is 10.
ran.dist.Hoyt([q[, omega]])
Generator for the Hoyt distribution (also known as Nakagami-q distribution): f(x; q, \omega) = \frac{2q^q}{\Gamma(q) \omega^q} x^{2q - 1} e^{-\frac{q}{\omega} x^2}, where q \in (0, 1] and \omega > 0 . Support: x > 0 .

Parameters

NameTypeDescription
qnumberShape parameter. Default value is 0.5.
omeganumberSpread parameter. Default value is 1.
ran.dist.HyperbolicSecant()
Generator for the hyperbolic secant distribution: f(x) = \frac{1}{2}\mathrm{sech}\Big(\frac{\pi}{2} x\Big). Support: x \in \mathbb{R} .
ran.dist.Hyperexponential([parameters])
Generator for the hyperexponential distribution: f(x; {w}, {\lambda}) = \frac{1}{\sum_j w_j} \sum_i w_i \lambda_i e^{-\lambda_i x}, where w_i, \lambda_i > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
parametersObject[]Array containing the rates and corresponding weights. Each array element must be an object with twp properties: weight and rate. Default value is [{weight: 1, rate: 1}, {weight: 1, rate: 1}].
ran.dist.Hypergeometric([N[, K[, n]]])
Generator for the hypergeometric distribution: f(k; N, K, r) = \frac{\begin{pmatrix}K \\ k \\ \end{pmatrix} \begin{pmatrix}N - k \\ n - k \\ \end{pmatrix}}{\begin{pmatrix}N \\ n \\ \end{pmatrix}}, with N \in \mathbb{N}^+ , K \in {0, 1, ..., N} and n \in {0, 1, ..., N} . Support: k \in {\mathrm{max}(0, n+K-N), ..., \mathrm{min}(n, K)} .

Parameters

NameTypeDescription
NnumberTotal number of elements to sample from. If not an integer, it is rounded to the nearest one. Default value is 10.
KnumberTotal number of successes. If not an integer, it is rounded to the nearest one. Default value is 5.
nnumberIf not an integer, it is rounded to the nearest one. Number of draws. Default value is 5.
ran.dist.InverseChi2([nu])
Generator for the inverse \chi^2 distribution: f(x; \nu) = \frac{2^{-\nu/2}}{\Gamma(\nu / 2)} x^{-\nu/2 - 1} e^{-1/(2x)}, with \nu \in \mathbb{N}^+ . Support: x > 0 .

Parameters

NameTypeDescription
nunumberDegrees of freedom. Default value is 1.
ran.dist.InverseGamma([alpha[, beta]])
Generator for the inverse gamma distribution: f(x; \alpha, \beta) = \frac{\beta^\alpha}{\Gamma(\alpha)} x^{-\alpha - 1} e^{-\beta/x}, where \alpha, \beta > 0 . Support: x > 0 .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 1.
betanumberScale parameter. Default value is 1.
ran.dist.InverseGaussian([mu[, lambda]])
Generator for the Wald or inverse Gaussian distribution: f(x; \lambda, \mu) = \bigg[\frac{\lambda}{2 \pi x^3}\bigg]^{1/2} e^{\frac{-\lambda (x - \mu)^2}{2 x \mu^2}}, with \mu, \lambda > 0 . Support: x > 0 .

Parameters

NameTypeDescription
munumberMean of the distribution. Default value is 1.
lambdanumberShape parameter. Default value is 1.
ran.dist.InvertedWeibull([c])
Generator for the inverted Weibull distribution: f(x; c) = c x^{-c - 1} e^{-x^{-c}}, with c > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
cnumberShape parameter. Default value is 2.
ran.dist.IrwinHall([n])
Generator for the Irwin-Hall distribution: f(x; n) = \frac{1}{(n - 1)!} \sum_{k = 0}^{\lfloor x\rfloor} (-1)^k \begin{pmatrix}n \\ k \\ \end{pmatrix} (x - k)^{n - 1}, with n \in \mathbb{N}^+ . Support: x \in [0, n] .

Parameters

NameTypeDescription
nnumberNumber of uniform variates to sum. If not an integer, it is rounded to the nearest one. Default value is 1.
ran.dist.JohnsonSB([gamma[, delta[, lambda[, xi]]]])
Generator for Johnson's S_B distribution: f(x; \gamma, \delta, \lambda, \xi) = \frac{\delta \lambda}{\sqrt{2 \pi} z (\lambda - z)} e^{-\frac{1}{2}\big[\gamma + \delta \ln \frac{z}{\lambda - z}\big]^2}, with \gamma, \xi \in \mathbb{R} , \delta, \lambda > 0 and z = x - \xi . Support: x \in (\xi, \xi + \lambda) .

Parameters

NameTypeDescription
gammanumberFirst location parameter. Default value is 0.
deltanumberFirst scale parameter. Default value is 1.
lambdanumberSecond scale parameter. Default value is 1.
xinumberSecond location parameter. Default value is 0.
ran.dist.JohnsonSU([gamma[, delta[, lambda[, xi]]]])
Generator for Johnson's S_U distribution: f(x; \gamma, \delta, \lambda, \xi) = \frac{\delta}{\lambda \sqrt{2 \pi}} \frac{e^{-\frac{1}{2}\big[\gamma + \delta \mathrm{sinh}^{-1} z \big]^2}}{\sqrt{1 + z^2}}, with \gamma, \xi \in \mathbb{R} , \delta, \lambda > 0 and z = \frac{x - \xi}{\lambda} . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
gammanumberFirst location parameter. Default value is 0.
deltanumberFirst scale parameter. Default value is 1.
lambdanumberSecond scale parameter. Default value is 1.
xinumberSecond location parameter. Default value is 0.
ran.dist.Kolmogorov()
Generator for the Kolmogorov distribution: f(x) = 8 \sum_{k=1}^\infty (-1)^{k - 1} k^2 x e^{-2 k^2 x^2}. Support: x > 0 .
ran.dist.Kumaraswamy([alpha[, beta]])
Generator for the Kumaraswamy distribution (also known as Minimax distribution): f(x; a, b) = a b x^{a-1} (1 - x^a)^{b - 1}, with a, b > 0 . Support: x \in (0, 1) .

Parameters

NameTypeDescription
alphanumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 1.
ran.dist.Laplace([mu[, b]])
Generator for the Laplace distribution (also known as double exponential distribution): f(x; \mu, b) = \frac{1}{2b}e^{-\frac{|x - \mu|}{b}}, where \mu \in \mathbb{R} and b > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
bnumberScale parameter. Default value is 1.
ran.dist.Levy([mu[, c]])
Generator for the Lévy distribution: f(x; \mu, c) = \sqrt{\frac{c}{2 \pi}}\frac{e^{-\frac{c}{2(x - \mu)}}}{(x - \mu)^{3/2}}, with \mu \in \mathbb{R} and c > 0 . Support: x \in [\mu, \infty) .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
cnumberScale parameter. Default value is 1.
ran.dist.Lindley([theta])
Generator for the Lindley distribution: f(x; \theta) = \frac{\theta^2}{1 + \theta} (1 + x) e^{-\theta x}, with \theta > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
thetanumberShape parameter. Default value is 1.
ran.dist.Logarithmic([a[, b]])
Generator for the (continuous) logarithmic distribution: f(x; a, b) = \frac{\ln x}{a (1 - \ln a) - b (1 - \ln b)}, with a, b \in [1, \infty) and a < b . Support: x \in [a, b] .

Parameters

NameTypeDescription
anumberLower boundary of the distribution. Default value is 1.
bnumberUpper boundary of the distribution. Default value is 2.
ran.dist.LogCauchy([mu[, sigma]])
Generator for the log-Cauchy distribution: f(x; \mu, \sigma) = \frac{1}{\pi x}\bigg[\frac{\sigma}{(\ln x - \mu)^2 + \sigma^2}\bigg], with \mu \in \mathbb{R} and \sigma > 0 . Support: x > 0 .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
sigmanumberScale parameter. Default value is 1.
ran.dist.LogGamma([alpha[, beta[, mu]]])
Generator for the log-gamma distribution using the shape/rate parametrization: f(x; \alpha, \beta, \mu) = \frac{\beta^\alpha}{\Gamma(\alpha)} \ln^{\alpha - 1}(x - \mu + 1) (x - \mu + 1)^{-(1 + \beta)}, where \alpha, \beta > 0 and \mu \ge 0 . Support: x \in [\mu, \infty) .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 1.
betanumberRate parameter. Default value is 1.
munumberLocation parameter. Default value is 0.
ran.dist.Logistic([mu[, s]])
Generator for the logistic distribution: f(x; \mu, s) = \frac{e^{-z}}{s (1 + e^{-z})^2}, with z = \frac{x - \mu}{s} , \mu \in \mathbb{R} and s > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
snumberScale parameter. Default value is 1.
ran.dist.LogisticExponential([lambda[, kappa]])
Generator for the logistic-exponential distribution: f(x; \lambda, \kappa) = \frac{\lambda \kappa (e^{\lambda x} - 1)^{\kappa - 1} e^{\lambda x}}{[1 + (e^{\lambda x} - 1)^\kappa]^2}, where \lambda, \kappa > 0 . Support: x > 0 .

Parameters

NameTypeDescription
lambdanumberScale parameter. Default value is 1.
kappanumberShape parameter. Default value is 1.
ran.dist.LogitNormal([mu[, sigma]])
Generator for the logit-normal distribution: f(x; \mu, \sigma) = \frac{1}{\sigma \sqrt{2 \pi} x (1 - x)} e^{-\frac{[\mathrm{logit}(x) - \mu]^2}{2 \sigma^2}}, with \mu \in \mathbb{R} , \sigma > 0 and \mathrm{logit}(x) = \ln \frac{x}{1 - x} . Support: x \in (0, 1) .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
sigmanumberScale parameter. Default value is 1.
ran.dist.LogLaplace([mu[, b]])
Generator for the log-Laplace distribution: f(x; \mu, b) = \frac{1}{2bx}e^{-\frac{|\mathrm{ln} x - \mu|}{b}}, where \mu \in \mathbb{R} and b > 0 . Support: x > 0 .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
bnumberScale parameter. Default value is 1.
ran.dist.LogLogistic([alpha[, beta]])
Generator for the log-logistic distribution (also known as Fisk distribution): f(x; \alpha, \beta) = \frac{(\beta / \alpha) (x / \alpha)^{\beta - 1}}{[1 + (x / \alpha)^\beta]^2}, with \alpha, \beta > 0 . Support: x \in [0, \infty) .

Parameters

NameTypeDescription
alphanumberScale parameter. Default value is 1.
betanumberShape parameter. Default value is 1.
ran.dist.LogNormal([mu[, sigma]])
Generator for the log-normal distribution: f(x; \mu, \sigma) = \frac{1}{x \sigma \sqrt{2 \pi}}e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}, where \mu \in \mathbb{R} and \sigma > 0 . Support: x > 0 .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
sigmanumberScale parameter. Default value is 1.
ran.dist.LogSeries([p])
Generator for the log-series distribution: f(k; p) = \frac{-1}{\ln(1 - p)}\frac{p^k}{k}, with p \in (0, 1) . Support: k \in \mathbb{N}^+ .

Parameters

NameTypeDescription
pnumberDistribution parameter. Default value is 0.5.
ran.dist.Lomax([lambda[, alpha]])
Generator for the Lomax distribution: f(x; \lambda, \alpha) = \frac{\alpha}{\lambda}\bigg[1 + \frac{x}{\lambda}\bigg]^{-(\alpha + 1)}, with \lambda, \alpha > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
lambdanumberScale parameter. Default value is 1.
alphanumberShape parameter. Default value is 1.
ran.dist.Makeham([alpha[, beta[, lambda]]])
Generator for the Makeham distribution (also known as Gompertz-Makeham distribution): f(x; \alpha, \beta, \lambda) = (\alpha e^{\beta x} + \lambda) \exp\Big[{-\lambda x - \frac{\alpha}{\beta}(e^{\beta x} - 1)}\Big], with \alpha, \beta, \lambda > 0 . Support: x > 0 .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 1.
betanumberRate parameter. Default value is 1.
lambdanumberScale parameter. Default value is 1.
ran.dist.MaxwellBoltzmann([a])
Generator for the Maxwell-Boltzmann distribution: f(x; a) = \sqrt{\frac{2}{\pi}}\frac{x^2 e^{-x^2 / (2a^2)}}{a^3}, with a > 0 . Support: x > 0 .

Parameters

NameTypeDescription
anumberScale parameter. Default value is 1.
ran.dist.Mielke([k[, s]])
Generator for the Mielke distribution: f(x; k, s) = \frac{k x^{k - 1}}{(1 + x^s)^{1 + k/s}}, with k, s > 0 . Support: x > 0 . It can be viewed as a re-parametrization of the Dagum distribution.

Parameters

NameTypeDescription
knumberFirst shape parameter. Default value is 2.
snumberSecond shape parameter. Default value is 1.
ran.dist.Moyal([mu[, sigma]])
Generator for the Moyal distribution: f(x; \mu, \sigma) = \frac{1}{\sqrt{2 \pi}}e^{-\frac{1}{2}(z + e^{-z})}, where z = \frac{x - \mu}{\sigma} , \mu \in \mathbb{R} and \sigma > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
sigmanumberScale parameter. Default value is 1.
ran.dist.Muth([alpha])
Generator for the Muth distribution: f(x; \alpha) = (e^{\alpha x} - \alpha) \exp\bigg(\alpha x - \frac{1}{\alpha} (e^{\alpha x} - 1)\bigg), with \alpha \in (0, 1] . Support: x > 0 .

Parameters

NameTypeDescription
alphanumberShape parameter. Default value is 0.5.
ran.dist.Nakagami([m[, omega]])
Generator for the Nakagami distribution: f(x; m, \Omega) = \frac{2m^m}{\Gamma(m) \Omega^m} x^{2m - 1} e^{-\frac{m}{\Omega} x^2}, where m \in \mathbb{R} , m \ge 0.5 and \Omega > 0 . Support: x > 0 .

Parameters

NameTypeDescription
mnumberShape parameter. Default value is 1.
omeganumberSpread parameter. Default value is 1.
ran.dist.NegativeBinomial([r[, p]])
Generator for the negative-binomial distribution (also known as Gamma-Poisson, Pascal or Pólya distribution): f(k; r, p) = \begin{pmatrix}k + r - 1 \\ k \\ \end{pmatrix} (1 - p)^r p^k, with r \in \mathbb{N}^+ and p \in [0, 1] . Support: k \in \mathbb{N}_0 .

Parameters

NameTypeDescription
rnumberNumber of failures until the experiment is stopped. If not an integer, it is rounded to the nearest integer. Default value is 10.
pnumberProbability of success. Default value is 0.5.
ran.dist.NegativeHypergeometric([N[, K[, r]]])
Generator for the negative hypergeometric distribution: f(k; N, K, r) = \frac{\begin{pmatrix}k + r - 1 \\ k \\ \end{pmatrix} \begin{pmatrix}N - r - k \\ K - k \\ \end{pmatrix}}{\begin{pmatrix}N \\ K \\ \end{pmatrix}}, with N \in \mathbb{N}_0 , K \in {0, 1, ..., N} and r \in {0, 1, ..., N - K} . Support: k \in {0, ..., K} .

Parameters

NameTypeDescription
NnumberTotal number of elements to sample from. If not an integer, it is rounded to the nearest one. Default value is 10.
KnumberTotal number of successes. If not an integer, it is rounded to the nearest one. Default value is 5.
rnumberTotal number of failures to stop at. If not an integer, it is rounded to the nearest one. Default value is 5.
ran.dist.NeymanA([lambda[, phi]])
Generator for the Neyman type A distribution: f(k; \lambda, \phi) = \frac{e^{-\lambda + \lambda e^{-\phi}} \phi^k}{k!} \sum_{j=1}^k S(k, j) \lambda^k e^{-\phi k}, where \lambda, \theta > 0 and S(n, m) denotes the Stirling number of the second kind. Support: k \in \mathbb{N}_0 .

Parameters

NameTypeDescription
lambdanumberMean of the number of clusters. Default value is 1.
phinumberMean of the cluster size. Default value is 1.
ran.dist.NoncentralBeta([alpha[, beta[, lambda]]])
Generator for the non-central beta distribution: f(x; \alpha, \beta, \lambda) = e^{-\frac{\lambda}{2}} \sum_{k = 0}^\infty \frac{1}{k!} \bigg(\frac{\lambda}{2}\bigg)^k \frac{x^{\alpha + k - 1} (1 - x)^{\beta - 1}}{\mathrm{B}(\alpha + k, \beta)}, where \alpha, \beta > 0 and \lambda \ge 0 . Support: x \in [0, 1] .

Parameters

NameTypeDescription
alphanumberFirst shape parameter. Default value is 1.
betanumberSecond shape parameter. Default value is 1.
lambdanumberNon-centrality parameter. Default value is 1.
ran.dist.NoncentralChi([k[, lambda]])
Generator for the non-central \chi distribution: f(x; k; \lambda) = \frac{x^k \lambda}{(\lambda x)^{k/2}} e^{-\frac{x^2 + \lambda^2}{2}} I_{k/2 - 1}(\lambda x), with k \in \mathbb{N}^+ , \lambda > 0 and I_n(x) is the modified Bessel function of the first kind with order n . Support: x \in [0, \infty) .

Parameters

NameTypeDescription
knumberDegrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
lambdanumberNon-centrality parameter. Default value is 1.
ran.dist.NoncentralChi2([k[, lambda]])
Generator for the non-central \chi^2 distribution: f(x; k; \lambda) = \frac{1}{2}e^{-\frac{x + \lambda}{2}} \bigg(\frac{x}{\lambda}\bigg)^{k/4 - 1/2} I_{k/2 - 1}\big(\sqrt{\lambda x}\big), with k \in \mathbb{N}^+ , \lambda > 0 and I_n(x) is the modified Bessel function of the first kind with order n . Support: x \in [0, \infty) .

Parameters

NameTypeDescription
knumberDegrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
lambdanumberNon-centrality parameter. Default value is 1.
ran.dist.NoncentralF([d1[, d2[, lambda]]])
Generator for the non-central F distribution: f(x; d_1, d_2, \lambda) = e^{-\frac{\lambda}{2}} \sum_{k=0}^\infty \frac{1}{k!} \bigg(\frac{\lambda}{2}\bigg)^k \frac{\Big(\frac{d_1}{d_2}\Big)^{\frac{d_1}{2} + k} \Big(\frac{d_2}{d_2 + d_1 x}\Big)^{\frac{d_1 + d_2}{2} + k}}{\mathrm{B}\Big(\frac{d_2}{2}, \frac{d_1}{2} + k\Big)} x^{\frac{d_1}{2} -1 + k}, where d_1, d_2 \in \mathbb{N}^+ and \lambda > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
d1numberFirst degree of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
d2numberSecond degree of freedom. If not an integer, it is rounded to the nearest one. Default value is 2.
lambdanumberNon-centrality parameter. Default value is 1.
ran.dist.NoncentralT([nu[, mu]])
Generator for the non-central t distribution: f(x; \nu, \mu) = \frac{\nu^\frac{\nu}{2} \exp\Big(-\frac{\nu \mu^2}{2 (x^2 + \nu)}\Big)}{\sqrt{\pi} \Gamma\big(\frac{\nu}{2}\big) 2^\frac{\nu - 1}{2} (x^2 + \nu)^\frac{\nu + 1}{2}} \int_0^\infty y^\nu \exp\bigg(-\frac{1}{2}\bigg[y - \frac{\mu x}{\sqrt{x^2 + \nu}}\bigg]^2\bigg) \mathrm{d}y, with \nu \in \mathbb{N}^+ and \mu \in \mathbb{R} . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
nunumberDegrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 1.
munumberNon-centrality parameter. Default value is 1.
ran.dist.Normal([mu[, sigma]])
Generator for the normal distribution: f(x; \mu, \sigma) = \frac{1}{\sqrt{2 \pi \sigma^2}} e^{-\frac{(x - \mu)^2}{2\sigma^2}}, with \mu \in \mathbb{R} and \sigma > 0 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
munumberLocation parameter (mean). Default value is 0.
sigmanumberSquared scale parameter (variance). Default value is 1.
ran.dist.Pareto([xmin[, alpha]])
Generator for the Pareto distribution: f(x; x_\mathrm{min}, \alpha) = \frac{\alpha x_\mathrm{min}^\alpha}{x^{\alpha + 1}}, with x_\mathrm{min}, \alpha > 0 . Support: x \in [x_\mathrm{min}, \infty) .

Parameters

NameTypeDescription
xminnumberScale parameter. Default value is 1.
alphanumberShape parameter. Default value is 1.
ran.dist.PERT([a[, b[, c]]])
Generator for the PERT distribution: f(x; a, b, c) = \frac{(x - a)^{\alpha - 1} (c - x)^{\beta - 1}}{\mathrm{B}(\alpha, \beta) (c - a)^{\alpha + \beta + 1}}, where a, b, c \in \mathbb{R} , a < b < c , \alpha = \frac{4b + c - 5a}{c - a} , \beta = \frac{5c - a -4b}{c - a} and \mathrm{B}(x, y) is the beta function. Support: x \in [a, c] .

Parameters

NameTypeDescription
anumberLower boundary of the support. Default value is 0.
bnumberMode of the distribution. Default value is 0.5.
cnumberUpper boundary of the support. Default value is 1.
ran.dist.Poisson([lambda])
Generator for the Poisson distribution: f(k; \lambda) = \frac{\lambda^k e^{-\lambda}}{k!}, with \lambda > 0 . Support: k \in \mathbb{N}_0 .

Parameters

NameTypeDescription
lambdanumberMean of the distribution. Default value is 1.
ran.dist.PolyaAeppli([lambda[, theta]])
Generator for the Pólya-Aeppli distribution (also known as geometric Poisson distribution): f(k; \lambda, \theta) = \begin{cases}e^{-\lambda} &\quad\text{if $k = 0$},\\ e^{-\lambda} \sum_{j = 1}^k \frac{\lambda^j}{j!} \begin{pmatrix}k - 1 \\ j - 1 \\ \end{pmatrix} \theta^{k - j} (1 - \theta)^j &\quad\text{otherwise}\\ \end{cases}, where \lambda > 0 and \theta \in (0, 1) . Support: k \in \mathbb{N}_0 .

Parameters

NameTypeDescription
lambdanumberMean of the Poisson component. Default value is 1.
thetanumberParameter of the shifted geometric component. Default value is 0.5.
ran.dist.PowerLaw([a])
Generator for the power-law distribution (also called power-law distribution): f(x; a) = a x^{a - 1}, with a > 0 . Support: x \in (0, 1) . It is a special case of the Kumaraswamy distribution.

Parameters

NameTypeDescription
anumberOne plus the exponent of the distribution. Default value is 1.
ran.dist.QExponential([q[, lambda]])
Generator for the q-exponential distribution: f(x; q, \lambda) = (2 - q) \lambda e^{-\lambda x}_q, where q < 2 , \lambda > 0 and e^x_q denotes the q-exponential function. Support: x > 0 if q \ge 1 , otherwise x \in \big[0, \frac{1}{\lambda (1 - q)}\big) .

Parameters

NameTypeDescription
qnumberShape parameter. Default value is 1.5.
lambdanumberRate parameter. Default value is 1.
ran.dist.R([c])
Generator for the R distribution: f(x; c) = \frac{(1 - x^2)^{\frac{c}{2} - 1}}{\mathrm{B}\big(\frac{1}{2}, \frac{c}{2}\big)}, where c > 0 . Support: x \in [-1, 1] .

Parameters

NameTypeDescription
cnumberShape parameter. Default value is 1.
ran.dist.Rademacher()
Generator for the Rademacher distribution: f(k) = \begin{cases}1/2 &\quad\text{if $k = -1$},\\ 1/2 &\quad\text{if $k = 1$},\\ 0 &\quad\text{otherwise}.\\ \end{cases} Support: k \in {-1, 1} .
ran.dist.RaisedCosine([mu[, s]])
Generator for the raised cosine distribution: f(x; \mu, s) = \frac{1}{2s} \Big[1 + \cos\Big(\frac{x - \mu}{s} \pi\Big)\Big], where \mu \in \mathbb{R} and s > 0 . Support: x \in [\mu - s, \mu + s] .

Parameters

NameTypeDescription
munumberLocation paramter. Default value is 0.
snumberScale parameter. Default value is 1.
ran.dist.Rayleigh([sigma])
Generator for the Rayleigh distribution: f(x; \sigma) = \frac{x}{\sigma^2} e^{-\frac{x^2}{2\sigma^2}}, with \sigma > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
sigmanumberScale parameter. Default value is 1.
ran.dist.Reciprocal([a[, b]])
Generator for the reciprocal distribution: f(x; a, b) = \frac{1}{x [\ln b - \ln a]}, with a, b > 0 and a < b . Support: x \in [a, b] .

Parameters

NameTypeDescription
anumberLower boundary of the support. Default value is 1.
bnumberUpper boundary of the support. Default value is 2.
ran.dist.ReciprocalInverseGaussian([mu[, lambda]])
Generator for the reciprocal inverse Gaussian distribution (RIG): f(x; \lambda, \mu) = \bigg[\frac{\lambda}{2 \pi x}\bigg]^{1/2} e^{\frac{-\lambda (1 - \mu x)^2}{2 \mu^2 x}}, with \mu, \lambda > 0 . Support: x > 0 .

Parameters

NameTypeDescription
munumberMean of the inverse Gaussian distribution. Default value is 1.
lambdanumberShape parameter. Default value is 1.
ran.dist.Rice([nu[, sigma]])
Generator for the Rice distribution: f(x; \nu, \sigma) = \frac{x}{\sigma^2} e^{-\frac{x^2 + \nu^2}{2 \sigma^2}} I_0\bigg(\frac{\nu x}{\sigma^2}\bigg), with \nu, \sigma > 0 and I_0(x) is the modified Bessel function of the first kind with order zero. Support: x \in [0, \infty) .

Parameters

NameTypeDescription
nunumberFirst shape parameter. Default value is 1.
sigmanumberSecond shape parameter. Default value is 1.
ran.dist.ShiftedLogLogistic([mu[, sigma[, xi]]])
Generator for the shifted log-logistic distribution: f(x; \mu, \sigma, \xi) = \frac{(1 + \xi z)^{-(1/\xi + 1)}}{\sigma [1 + (1 + \xi z)^{-1/\xi}]^2}, with z = \frac{x - \mu}{\sigma} , \mu, \xi \in \mathbb{R} and \sigma > 0 . Support: x \ge \mu - \sigma/\xi if \xi > 0 , x \le \mu - \sigma/\xi if \xi < 0 , x \in \mathbb{R} otherwise.

Parameters

NameTypeDescription
munumberLocation parameter. Default value is 0.
sigmanumberScale parameter. Default value is 1.
xinumberShape parameter. Default value is 1.
ran.dist.Skellam([mu1[, mu2]])
Generator for the Skellam distribution: f(k; \mu_1, \mu_2) = e^{-(\mu_1 + \mu_2)}\Big(\frac{\mu_1}{\mu_2}\Big)^{k/2} I_k(2 \sqrt{\mu_1 \mu_2}), with \mu_1, \mu_2 \ge 0 and I_n(x) is the modified Bessel function of the first kind with order n . Support: k \in \mathbb{N} .

Parameters

NameTypeDescription
mu1numberMean of the first Poisson distribution. Default value is 1.
mu2numberMean of the second Poisson distribution. Default value is 1.
ran.dist.SkewNormal([xi[, omega[, alpha]]])
Generator for the skew normal distribution: f(x; \xi, \omega, \alpha) = \frac{2}{\omega} \phi\bigg(\frac{x - \xi}{\omega}\bigg) \Phi\bigg(\alpha \frac{x - \xi}{\omega}\bigg), where \xi, \alpha \in \mathbb{R} , \omega > 0 and \phi(x) , \Phi(x) denote the probability density and cumulative distribution functions of the standard normal distribution. Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
xinumberLocation parameter. Default value is 0.
omeganumberScale parameter. Default value is 1.
alphanumberShape parameter. Default value is 1.
ran.dist.Slash()
Generator for the slash distribution: f(x) = \begin{cases}\frac{\phi(0) - \phi(x)}{x^2} &\quad\text{if $x \ne 0$},\\ \frac{1}{2 \sqrt{2 \pi}} &\quad\text{if $x = 0$}\\ \end{cases}, where \phi(x) is the probability density function of the standard normal distribution. Support: x \in \mathbb{R} .
ran.dist.Soliton([N])
Generator for the (ideal) soliton distribution: f(k; N) = \begin{cases}\frac{1}{N} &\quad\text{if $k = 1$},\\ \frac{1}{k (1 - k)} &\quad\text{otherwise}\\ \end{cases}, with N \in \mathbb{N}^+ . Support: k \in {1, 2, ..., N} .

Parameters

NameTypeDescription
NnumberNumber of blocks in the messaging model. If not an integer, it is rounded to the nearest one. Default value is 1.
ran.dist.StudentT([nu])
Generator for Student's t-distribution: f(x; \nu) = \frac{1}{\sqrt{\nu}\mathrm{B}\big(\frac{1}{2}, \frac{\nu}{2}\big)} \Big(1 + \frac{x^2}{\nu}\Big)^{-\frac{\nu + 1}{2}}, with \nu > 0 and \mathrm{B}(x, y) is the beta function. Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
nunumberDegrees of freedom. Default value is 1.
ran.dist.StudentZ([n])
Generator for Student's Z distribution: f(x; n) = \frac{\Gamma\Big(\frac{n}{2}\Big)}{\sqrt{\pi} \Gamma\Big(\frac{n - 1}{2}\Big)} (1 + x^2)^{-\frac{n}{2}}, with n > 1 . Support: x \in \mathbb{R} .

Parameters

NameTypeDescription
nnumberDegrees of freedom. Default value is 2.
ran.dist.Trapezoidal([a[, b[, c[, d]]]])
Generator for the trapezoidal distribution: f(x; a, b, c, d) = \begin{cases}0 &\quad\text{for $x < a$},\\ \frac{2 (x - a)}{(b - a) (d + c - a - b)} &\quad\text{for $a \le x < b$}\\ \frac{2}{d + c - a - b} &\quad\text{for $b \le x < c$}\\ \frac{2 (d - x)}{(d - c) (d + c - a - b)} &\quad\text{for $c \le x \le d$}\\ 0 &\quad\text{for $d < x$} \\ \end{cases}, where a, b, c, d \in \mathbb{R} , a < d , a \le b < c and c \le d . Support: x \in [a, d] .

Parameters

NameTypeDescription
anumberLower bound of the support. Default value is 0.
bnumberStart of the level part. Default value is 0.33.
cnumberEnd of the level part. Default value is 0.67.
dnumberUpper bound of the support. Default value is 1.
ran.dist.Triangular([a[, b[, c]]])
Generator for the asymmetric triangular distribution: f(x; a, b, c) = \begin{cases}0 &\quad\text{for $x < a$},\\ \frac{2 (x - a)}{(b - a) (c - a)} &\quad\text{for $a \le x < c$} \\ \frac{2 (b - x)}{(b - a) (b - c)} &\quad\text{for $c \le x \le b$} \\ 0 &\quad\text{for $b < x$} \\ \end{cases}, with a, b, c \in \mathbb{R} , a < b and a \le c \le b . Support: x \in [a, b] .

Parameters

NameTypeDescription
anumberLower bound of the support. Default value is 0.
bnumberUpper bound of the support. Default value is 1.
cnumberMode of the distribution. Default value is 0.5.
ran.dist.TruncatedNormal([mu[, sigma[, a[, b]]]])
Generator for the truncated normal distribution: f(x; \mu, \sigma, a, b) = \frac{\phi(\xi)}{\Phi(\beta) - \Phi(\alpha)}, where \xi = \frac{x - \mu}{\sigma}, \alpha = \frac{a - \mu}{\sigma} and \beta = \frac{b - \mu}{\sigma} . The functions \phi and \Phi denote the probability density and cumulative distribution functions of the normal distribution. Finally, \mu \in \mathbb{R} , \sigma > 0 and b > a . Support: x \in [a, b] .

Parameters

NameTypeDescription
munumberMean of the underlying normal distribution. Default value is 0.
sigmanumberVariance of the underlying normal distribution. Default value is 1.
anumberLower boundary of the support. Default value is 0.
bnumberUpper boundary of the support. Default value is 1.
ran.dist.TukeyLambda([lambda])
Generator for the Tukey lambda distribution: f(x; \lambda) = \frac{1}{Q^{-1}(F(x))}, where Q(p) = \frac{p^\lambda - (1 - p)^\lambda}{\lambda} and F(x) = Q^{-1}(x) . Support: x \in [-1/\lambda, 1/\lambda] if \lambda > 0 , otherwise x \in \mathbb{R} .

Parameters

NameTypeDescription
lambdanumberShape parameter. Default value is 1.5.
ran.dist.Uniform([xmin[, xmax]])
Generator for the continuous uniform distribution: f(x; x_\mathrm{min}, x_\mathrm{max}) = \frac{1}{x_\mathrm{max} - x_\mathrm{min}}, with x_\mathrm{min}, x_\mathrm{max} \in \mathbb{R} and x_\mathrm{min} < x_\mathrm{max} . Support: x \in [x_\mathrm{min}, x_\mathrm{max}] .

Parameters

NameTypeDescription
xminnumberLower boundary. Default value is 0.
xmaxnumberUpper boundary. Default value is 1.
ran.dist.UniformRatio()
Generator for the uniform ratio distribution: f(x) = \begin{cases}\frac{1}{2} &\quad\text{if $x < 1$},\\ \frac{1}{2x^2} &\quad\text{if $x \ge 1$},\\ \end{cases}. Support: x > 0 .
ran.dist.UQuadratic([a[, b]])
Generator for the u-quadratic distribution: f(x; a, b) = \alpha (x - \beta)^2, where \alpha = \frac{12}{(b - a)^3} , \beta = \frac{a + b}{2} , a, b \in \mathbb{R} and a < b . Support: x \in [a, b] .

Parameters

NameTypeDescription
anumberLower bound of the support. Default value is 0.
bnumberUpper bound of the support. Default value is 1.
ran.dist.VonMises([kappa])
Generator for the von Mises distribution: f(x; \kappa) = \frac{e^{\kappa \cos(x)}}{2 \pi I_0(\kappa)}, with \kappa > 0 . Support: x \in [-\pi, \pi] . Note that originally this distribution is periodic and therefore it is defined over \mathbb{R} , but (without the loss of general usage) this implementation still does limit the support on the bounded interval [-\pi, \pi] .

Parameters

NameTypeDescription
kappanumberShape parameter. Default value is 1.
ran.dist.Weibull([lambda[, k]])
Generator for the Weibull distribution: f(x; \lambda, k) = \frac{k}{\lambda}\bigg(\frac{x}{\lambda}\bigg)^{k - 1} e^{-(x / \lambda)^k}, with \lambda, k > 0 . Support: x \ge 0 .

Parameters

NameTypeDescription
lambdanumberScale parameter. Default value is 1.
knumberShape parameter. Default value is 1.
ran.dist.Wigner([R])
Generator for Wigner distribution (also known as semicircle distribution): f(x; R) = \frac{2}{\pi R^2} \sqrt{R^2 - x^2}, with R > 0 . Support: x \in [-R, R] .

Parameters

NameTypeDescription
RnumberRadius of the distribution. Default value is 1.
ran.dist.YuleSimon([rho])
Generator for the Yule-Simon distribution: f(k; \rho) = \rho \mathrm{B}(k, \rho + 1), with \rho > 0 and \mathrm{B}(x, y) is the beta function. Support: k \in \mathbb{N}^+ .

Parameters

NameTypeDescription
rhonumberShape parameter. Default value is 1.
ran.dist.Zeta([s])
Generator for the zeta distribution: f(k; s) = \frac{k^{-s}}{\zeta(s)}, with s \in (1, \infty) and \zeta(x) is the Riemann zeta function. Support: k \in \mathbb{N}^+ .

Parameters

NameTypeDescription
snumberExponent of the distribution. Default value is 3.
ran.dist.Zipf([s[, N]])
Generator for the Zipf distribution: f(k; s, N) = \frac{k^{-s}}{H_{N, s}}, with s \ge 0 , N \in \mathbb{N}^+ and H_{N, s} denotes the generalized harmonic number. Support: k \in {1, 2, ..., N} .

Parameters

NameTypeDescription
snumberExponent of the distribution. Default value is 1.
NnumberNumber of words. If not an integer, it is rounded to the nearest integer. Default is 100.
ran.location.geometricMean(values)
Calculates the geometric mean of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate geometric mean for.

Returns

numberundefined
Gemoetric mean of the values if there are any, undefined otherwise.

Examples

ran.location.geometricMean([])
// => undefined

ran.location.geometricMean([1, 2, 3])
// => 1.8171205928321394
ran.location.harmonicMean(values)
Calculates the harmonic mean of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate harmonic mean for.

Returns

numberundefined
Harmonic mean of the values if there are any, undefined otherwise.

Examples

ran.location.harmonicMean([])
// => undefined

ran.location.harmonicMean([0, 1, 2])
// => undefined

run.location.harmonicMean([-1, 2, 3])
// => undefined

ran.location.harmonicMean([1, 2, 3])
// => 1.6363636363636365
ran.location.mean(values)
Calculates the arithmetic mean of an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate mean for.

Returns

numberundefined
Mean of the values if there are any, undefined otherwise.

Examples

ran.location.mean([])
// => undefined

ran.location.mean([1, 2, 3])
// => 2
ran.location.median(values)
Calculates the median of a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate median for.

Returns

number
Median of the values if there are any, undefined otherwise.

Examples

ran.location.median([])
// => undefined

ran.location.median([1, 2, 3, 4])
// => 2.5
ran.location.midrange(values)
Calculates the mid-range for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate mid-range for.

Returns

numberundefined
The mid-range of the values if there is any, undefined otherwise.

Examples

ran.location.midrange([])
// => undefined

ran.location.midrange([0, 0, 0, 1, 2])
// => 1
ran.location.mode(values)
Calculates the mode(s) of a sample. In case of discrete values (integers), it returns the values corresponding to the highest frequencies in ascending order. For continuous sample, the mode is estimated using the half-sample mode algorithm.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate mode for.

Returns

numbernumber[]undefined
The estimated mode (continuous sample), an array of modes (discrete sample) or undefined (empty sample).

Examples

ran.location.mode([])
// => undefined

ran.location.mode([1])
// => [1]

ran.location.mode([1, 1, 2, 2, 3])
// => [1, 2]

ran.location.mode([1, 2, 2, 2, 3])
// => [2]

ran.location.mode([1.2, 3.4, 5.6])
// => 4.5
ran.location.trimean(values)
Calculates the trimean for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate trimean for.

Returns

numberundefined
The trimean of the values if there is any, undefined otherwise.

Examples

ran.location.trimean([])
// => undefined

ran.location.trimean([1, 1, 1, 2, 3])
// => 1.25
ran.shape.kurtosis(values)
Calculates the sample excess kurtosis which is unbiased for the normal distribution.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate kurtosis for.

Returns

numberundefined
The sample kurtosis of values if there are more than two and their variance is nonzero, undefined otherwise.

Examples

ran.shape.kurtosis([])
// => undefined

ran.shape.kurtosis([1, 2])
// => undefined

ran.shape.kurtosis([1, 1, 1])
// => undefined

ran.shape.kurtosis([1, 1, 3, 1, 1])
// => 5.000000000000003

ran.shape.kurtosis([1, 2, 2, 2, 1])
// => -3.3333333333333326
ran.shape.moment(values, k[, c])
Calculates the k-th raw moment for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate moment for.
knumberOrder of the moment.
cnumberValue to shift the distribution by before calculating the moment.

Returns

numberundefined
The k-th moment of the values if there is any, undefined otherwise.

Examples

ran.shape.moment([], 2)
// => undefined

ran.shape.moment([1, 2, 3], 0)
// => 1

ran.shape.moment([1, 2, 3], 2)
// => 4.666666666666667
ran.shape.quantile(values, p)
Calculates the quantile at 0 < p < 1 using the R-7 algorithm.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate quantile for.
pnumberValue to calculate quantile at.

Returns

numberundefined
The quantile of the sample if there is any, undefined otherwise.
ran.shape.rank(values)
Calculates the fractional rank for an array of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate ranks for.

Returns

numberundefined
The ranks of the values if there are any, undefined otherwise.

Examples

ran.shape.rank([])
// => undefined

ran.shape.rank([1, 2, 2, 3])
// => [1, 2.5, 2.5, 4]
ran.shape.skewness(values)
Calculates the Fisher-Pearson standardized sample skewness for a sample of values.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate skewness for.

Returns

numberundefined
The sample skewness of values if there are more than two and their variance is nonzero, undefined otherwise.

Examples

ran.shape.skewness([])
// => undefined

ran.shape.skewness([1, 2])
// => undefined

ran.shape.skewness([1, 1, 1])
// => undefined

ran.shape.skewness([1, 1, 1, 2])
// => 2

ran.shape.skewness([1, 2, 2, 2])
// => -2
ran.shape.yule(values)
Calculates Yule's coefficient which is a measure of skewness based on quantiles.

Parameters

NameTypeDescription
valuesnumber[]Array of values to calculate Yule's coefficient for.

Returns

numberundefined
Yule's coefficient of the values if the lower and upper quartiles differ, undefined otherwise.

Examples

ran.shape.yule([])
// => undefined

ran.shape.yule([1, 1, 1])
// => undefined

ran.shape.yule([1, 1, 1, 2])
// => 1

ran.shape.yule([1, 2, 2, 2])
// => -1
ran.test.bartlett(dataSets[, alpha])
Calculates the Bartlett statistics for multiple data sets.

Parameters

NameTypeDescription
dataSetsArray[]Array containing the data sets.
alphanumberConfidence level.

Returns

Object
Object containing the test statistics (chi2) and whether the data sets passed the null hypothesis that their variances are the same.

Throws

Error
If the number of data sets is less than 2.
Error
If the size of any data set is less than 2 elements.

Examples

let normal1 = new ran.dist.Normal(1, 2)
let normal2 = new ran.dist.Normal(1, 3)
let normal3 = new ran.dist.Normal(1, 5)

ran.test.bartlett([normal1.sample(100), normal1.sample(100), normal1.sample(100)], 0.1)
// => { stat: 0.09827551592930094, passed: true }

ran.test.bartlett([normal1.sample(100), normal2.sample(100), normal3.sample(100)], 0.1)
// => { stat: 104.31185521417476, passed: false }
ran.test.brownForsythe(dataSets[, alpha])
Calculates the Brown-Forsythe test statistic for multiple data sets.

Parameters

NameTypeDescription
dataSetsArray[]Array containing the data sets.
alphanumberConfidence level.

Returns

Object
Object containing the test statistics (W) and whether the data sets passed the null hypothesis that their variances are the same.

Throws

Error
If the number of data sets is less than 2.
Error
If the size of any data set is less than 2 elements.

Examples

let normal1 = new ran.dist.Normal(1, 2)
let normal2 = new ran.dist.Normal(1, 3)
let normal3 = new ran.dist.Normal(1, 5)

ran.test.brownForsythe([normal1.sample(100), normal1.sample(100), normal1.sample(100)], 0.1)
// => { stat: 1.0664885130451343, passed: true }

ran.test.brownForsythe([normal1.sample(100), normal2.sample(100), normal3.sample(100)], 0.1)
// => { stat: 27.495614343570345, passed: false }
ran.test.hsic(dataSets[, alpha])
Calculates the Hilbert-Schmidt independence criterion (HSIC) for paired arrays of values. HSIC tests if two data sets are statistically independent. Source: A. Gretton et al. A Kernel Statistical Test of Independence in Advances in Neural Information Processing Systems (2008).

Parameters

NameTypeDescription
dataSetsArray[]Array containing the two data sets.
alphanumberConfidence level.

Returns

Object
Object containing the test statistics and whether the data sets passed the null hypothesis that they are statistically independent.

Throws

Error
If the number of data sets is less than 2.
Error
If the data sets have different sample size.
Error
If the sample size is less than 6.

Examples

let sample1 = Array.from({length: 50}, (d, i) => i)
let sample2 = sample1.map(d => d + Math.random() - 0.5)
ran.test.hsic([sample1, sample2])
// => { stat: 6.197628059960943, passed: false }

sample1 = ran.core.float(0, 10, 50)
sample2 = ran.core.float(0, 10, 50)
ran.test.hsic([sample1, sample2])
// => { stat: 0.3876607680368274, passed: true }
ran.test.levene(dataSets[, alpha])
Calculates the Levene's test statistic for multiple data sets.

Parameters

NameTypeDescription
dataSetsArray[]Array containing the data sets.
alphanumberConfidence level.

Returns

Object
Object containing the test statistics (W) and whether the data sets passed the null hypothesis that their variances are the same.

Throws

Error
If the number of data sets is less than 2.
Error
If the size of any data set is less than 2 elements.

Examples

let normal1 = new ran.dist.Normal(1, 2)
let normal2 = new ran.dist.Normal(1, 3)
let normal3 = new ran.dist.Normal(1, 5)

ran.test.levene([normal1.sample(100), normal1.sample(100), normal1.sample(100)], 0.1)
// => { stat: 0.019917137672045088, passed: true }

ran.test.levene([normal1.sample(100), normal2.sample(100), normal3.sample(100)], 0.1)
// => { stat: 29.06345994086687, passed: false }
ran.test.mannWhitney(dataSets[, alpha])
Calculates the Mann-Whitney statistics for two data sets.

Parameters

NameTypeDescription
dataSetsArray[]Array containing the two data sets.
alphanumberConfidence level.

Returns

Object
Object containing the (non-standardized) test statistics (U) and whether the data sets passed the null hypothesis that the samples come from the same distribution.

Throws

Error
If the number of data sets is different from 2.

Examples

let pareto = new ran.dist.Pareto(1, 2)
let uniform = new ran.dist.Uniform(1, 10)

ran.test.mannWhitney([pareto.sample(100), pareto.sample(100)], 0.1)
// => { stat: 4941, passed: true }

ran.test.mannWhitney([pareto.sample(100), uniform.sample(100)], 0.1)
// => { stat: 132, passed: false }