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 ranjsuse in browser
<script type="text/javascript" src="ran.min.js"></script>demo
documentation
ran.core.char([string[, n]])
Samples some characters with replacement from a string with uniform distribution.
Parameters
| Name | Type | Description |
|---|---|---|
| string | string | String to sample characters from. |
| n | number | Number of characters to sample. |
Returns
stringstring[]undefinedRandom 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
| Name | Type | Description |
|---|---|---|
| values | Array | Array to sample from. |
| n | number | Number of elements to sample. |
Returns
objectobject[]undefinedSingle 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
| Name | Type | Description |
|---|---|---|
| head | Object | Head value. |
| tail | Object | Tail value. |
| p | number | Bias (probability of head). Default is 0.5. |
| n | number | Number 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
| Name | Type | Description |
|---|---|---|
| min | number | Lower boundary, or upper if max is not given. |
| max | number | Upper boundary. |
| n | number | Number 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
| Name | Type | Description |
|---|---|---|
| min | number | Lower boundary, or upper if max is not specified. |
| max | number | Upper boundary. |
| n | number | Number 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
| Name | Type | Description |
|---|---|---|
| value | numberstring | The 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
| Name | Type | Description |
|---|---|---|
| values | Array | Array to shuffle. |
Returns
ArrayThe 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
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. |
Returns
numberundefinedThe 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.166666666666668ran.dependence.dCor(x, y)
Calculates the distance correlation for paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. |
Returns
numberundefinedThe 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.5623413251903491ran.dependence.dCov(x, y)
Calculates the distance covariance for paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. |
Returns
numberundefinedThe 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.31426968052735443ran.dependence.kendall(x, y)
Calculates Kendall's rank correlation coefficient for paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. |
Returns
numberundefinedKendall'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.3333333333333333ran.dependence.kullbackLeibler(p, q)
Calculates the (discrete) Kullback-Leibler divergence for two probability distributions:
Parameters
| Name | Type | Description |
|---|---|---|
| p | number[] | Array representing the probabilities for the i-th value in the base distribution (P). |
| q | number[] | Array representing the probabilities for the i-th value in compared distribution (Q). |
Returns
numberundefinedThe 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.2396882491444514ran.dependence.oddsRatio(p00, p01, p10, p11)
Calculates the odds ratio for the joint probabilities of two binary variables:
Parameters
| Name | Type | Description |
|---|---|---|
| p00 | number | The probability of X = 0 and Y = 0. |
| p01 | number | The probability of X = 0 and Y = 1. |
| p10 | number | The probability of X = 1 and Y = 0. |
| p11 | number | The probability of X = 1 and Y = 1. |
Returns
numberundefinedThe 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.6666666666666669ran.dependence.pearson(x, y)
Calculates the Pearson correlation coefficient for paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. |
Returns
numberundefinedThe 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.6643835616438358ran.dependence.pointBiserial(x, y)
Calculates the point-biserial correlation coefficient for paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. Must contain 0s and 1s only. |
Returns
numberundefinedThe 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.8660254037844386ran.dependence.somersD(x, y)
Calculates Somers' D for paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. |
Returns
numberundefinedSomers' 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])
// => -1ran.dependence.spearman(x, y)
Calculates Spearman's rank correlation coefficient for two paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | First array of values. |
| y | number[] | Second array of values. |
Returns
numberundefinedSpearman'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])
// => 1ran.dependence.yuleQ(p00, p01, p10, p11)
Calculates Yule's Q for the joint probabilities of two binary variables:
Parameters
| Name | Type | Description |
|---|---|---|
| p00 | number | The probability of X = 0 and Y = 0. |
| p01 | number | The probability of X = 0 and Y = 1. |
| p10 | number | The probability of X = 1 and Y = 0. |
| p11 | number | The probability of X = 1 and Y = 1. |
Returns
numberundefinedYule'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.19999999999999984ran.dependence.yuleY(p00, p01, p10, p11)
Calculates Yule's Y for the joint probabilities of two binary variables:
Parameters
| Name | Type | Description |
|---|---|---|
| p00 | number | The probability of X = 0 and Y = 0. |
| p01 | number | The probability of X = 0 and Y = 1. |
| p10 | number | The probability of X = 1 and Y = 0. |
| p11 | number | The probability of X = 1 and Y = 1. |
Returns
numberundefinedYule'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.10102051443364372ran.dispersion.cv(values)
Calculates the coefficient of variation of an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate coefficient of variation for. |
Returns
numberundefinedCoefficient 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.5270462766947299ran.dispersion.dVar(x)
Calculates the distance variance for paired arrays of values.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number[] | Array of values. |
Returns
numberundefinedThe distance variance if the array os not empty, undefined otherwise.
Examples
ran.dependence.dVar([])
// => undefined
ran.dependence.dVar([1, 2, 3])
// => 0.7027283689263066ran.dispersion.entropy(probabilities[, base])
Calculates the Shannon entropy for a probability distribution.
Parameters
| Name | Type | Description |
|---|---|---|
| probabilities | number[] | Array representing the probabilities for the i-th value. |
| base | number | Base for the logarithm. If not specified, natural logarithm is used. |
Returns
numberundefinedEntropy 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.0888999753452238ran.dispersion.gini(values)
Calculates the Gini coefficient for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate the Gini coefficient for. |
Returns
numberundefinedThe 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.45ran.dispersion.iqr(values)
Calculates the interquartile range for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate the interquartile range for. |
Returns
numberundefinedThe interquartile range of the values if there is any, undefined otherwise.
Examples
ran.dispersion.iqr([])
// => undefined
ran.dispersion.iqr([1, 1, 2, 3, 3])
// => 2ran.dispersion.md(values)
Calculates the mean absolute difference of an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate mean absolute difference for. |
Returns
numberundefinedMean 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.25ran.dispersion.midhinge(values)
Calculates the midhinge for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate midhinge for. |
Returns
numberundefinedThe midhinge of the values if there is any, undefined otherwise.
Examples
ran.dispersion.midhinge([])
// => undefined
ran.dispersion.midhinge([1, 1, 1, 2, 3])
// => 1.5ran.dispersion.qcd(values)
Calculates the quartile coefficient of dispersion for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate quartile coefficient of dispersion for. |
Returns
numberundefinedThe 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.25ran.dispersion.range(values)
Calculates the range for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate range for. |
Returns
numberundefinedThe range of the values if there is any, undefined otherwise.
Examples
ran.dispersion.range([])
// => undefined
ran.dispersion.range([0, 1, 2, 2])
// => 2ran.dispersion.rmd(values)
Calculates the relative mean absolute difference of an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate relative mean absolute difference for. |
Returns
numberundefinedRelative 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.5ran.dispersion.stdev(values)
Calculates the unbiased standard deviation of an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate standard deviation for. |
Returns
numberundefinedStandard 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.5811388300841898ran.dispersion.variance(values)
Calculates the unbiased sample variance of an array of values using Welford's algorithm.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate variance for. |
Returns
numberundefinedVariance 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.5ran.dispersion.vmr(values)
Calculates the variance-to-mean ratio of an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate variance-to-mean ratio for. |
Returns
numberundefinedVariance-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.8333333333333334ran.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
| Name | Type | Description |
|---|---|---|
| data | number[] | Array of values containing the data. |
Returns
numberThe 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.0367230482957ran.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
| Name | Type | Description |
|---|---|---|
| data | number[] | Array of values containing the data. |
Returns
numberThe 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.5839264881165ran.dist.Distribution.cdf(x)
The cumulative distribution function:if the distribution is continuous andif it is discrete. The functions and denote the probability density and mass functions.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number | Value to evaluate CDF at. |
Returns
numberThe cumulative distribution value.
Examples
let pareto = new ran.dist.Pareto(1, 2)
pareto.cdf(3)
// => 0.8888888888888888ran.dist.Distribution.cHazard(x)
The cumulative hazard function:where is the hazard function.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number | Value to evaluate cumulative hazard at. |
Returns
numberThe cumulative hazard.
Examples
let pareto = new ran.dist.Pareto(1, 2)
pareto.cHazard(3)
// => 2.197224577336219ran.dist.Distribution.hazard(x)
The hazard function:where and are the probability density (or mass) function and the survival function, respectively.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number | Value to evaluate the hazard at. |
Returns
numberThe hazard value.
Examples
let pareto = new ran.dist.Pareto(1, 2)
pareto.hazard(3)
// => 0.6666666666666663ran.dist.Distribution.lnL(data)
The log-likelihood of the current distribution based on some data. More precisely:where is the set of observations (sample) and is the parameter vector of the distribution. The function denotes the probability density/mass function.
Parameters
| Name | Type | Description |
|---|---|---|
| data | number[] | Array of numbers to calculate log-likelihood for. |
Returns
numberThe 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.1174868780569ran.dist.Distribution.load(state)
Loads a new state for the generator.
Parameters
| Name | Type | Description |
|---|---|---|
| state | Object | The state to load. |
Returns
ran.dist.DistributionReference 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
| Name | Type | Description |
|---|---|---|
| x | number | Value to evaluate the log pdf at. |
Returns
numberThe logarithmic probability density (or mass).
Examples
let pareto = new ran.dist.Pareto(1, 2)
pareto.lnPdf(3)
// => -2.6026896854443837ran.dist.Distribution.pdf(x)
Probability density function. In case of discrete distributions, it is the probability mass function.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number | Value to evaluate distribution at. |
Returns
numberThe probability density or probability mass.
Examples
let pareto = new ran.dist.Pareto(1, 2)
pareto.pdf(3)
// => 0.07407407407407407ran.dist.Distribution.q(p)
The quantile function of the distribution. For continuous distributions, it is defined as the inverse of the distribution function:whereas for discrete distributions it is the lower boundary of the interval that satisfies :with 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 is solved using Brent's method. For discrete distributions a look-up table is used with linear search.
Parameters
| Name | Type | Description |
|---|---|---|
| p | number | The probability at which the quantile should be evaluated. |
Returns
numberundefinedThe value of the quantile function at the specified probability if and the quantile could be found, undefined otherwise.
ran.dist.Distribution.sample([n])
Generates some random variate.
Parameters
| Name | Type | Description |
|---|---|---|
| n | number | Number 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
ObjectObject 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
| Name | Type | Description |
|---|---|---|
| value | numberstring | The value of the seed, either a number or a string (for the ease of tracking seeds). |
Returns
ran.dist.DistributionReference 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:where denotes the cumulative distribution function.
Parameters
| Name | Type | Description |
|---|---|---|
| x | number | Value to evaluate survival function at. |
Returns
numberThe survival value.
Examples
let pareto = new ran.dist.Pareto(1, 2)
pareto.survival(3)
// => 0.11111111111111116ran.dist.Distribution.test(values)
Tests if an array of values is sampled from the specified distribution. For discrete distributions this method uses 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
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to test. |
Returns
ObjectObject with two properties representing the result of the test:
- {statistics}: The 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
stringDistribution type.
ran.dist.Alpha([alpha[, beta]])
Generator for the alpha distribution:where and denote the probability density and cumulative probability functions of the normal distribution. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 1. |
| beta | number | Scale parameter. Default value is 1. |
ran.dist.Anglit([mu[, beta]])
Generator for the anglit distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| beta | number | Scale parameter. Default value is 1. |
ran.dist.Arcsine([a[, b]])
Generator for the arbitrarily bounded arcsine distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Lower boundary. Default value is 0. |
| b | number | Upper boundary. Default value is 1. |
ran.dist.BaldingNichols([F[, p]])
Generator for the Balding-Nichols distribution:where , and . Support: . It is simply a re-parametrization of the beta distribution.
Parameters
| Name | Type | Description |
|---|---|---|
| F | number | Fixation index. Default value is 0.5. |
| p | number | Allele frequency. Default value is 0.5. |
ran.dist.Bates([n[, a[, b]]])
Generator for the Bates distribution:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| n | number | Number of uniform variates to sum. If not an integer, it is rounded to the nearest one. Default value is 10. |
| a | number | Lower boundary of the uniform variate. Default value is 0. |
| b | number | Upper boundary of the uniform variate. Default value is 1. |
ran.dist.Benini([alpha[, beta[, sigma]]])
Generator for the Benini distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 1. |
| sigma | number | Scale parameter. Default value is 1. |
ran.dist.BenktanderII([a[, b]])
Generator for the Benktander type II distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Scale parameter. Default value is 1. |
| b | number | Shape parameter. Default value is 0.5. |
ran.dist.Bernoulli([p])
Generator for the Bernoulli distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| p | number | Probability of the outcome 1. Default value is 0.5. |
ran.dist.Beta([alpha[, beta]])
Generator for the beta distribution:with and is the beta function. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 1. |
ran.dist.BetaBinomial([n[, alpha[, beta]]])
Generator for the beta-binomial distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| n | number | Number of trials. Default value is 10. |
| alpha | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 2. |
ran.dist.BetaPrime([alpha[, beta]])
Generator for the beta prime distribution (also known as inverted beta):with and is the beta function. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | First shape parameter. Default value is 2. |
| beta | number | Second shape parameter. Default value is 2. |
ran.dist.BetaRectangular([alpha[, beta[, theta[, a[, b]]]]])
Generator for the beta-rectangular distribution:with , , , and is the beta function. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 1. |
| theta | number | Mixture parameter. Default value is 0.5. |
| a | number | Lower boundary of the support. Default value is 0. |
| b | number | Upper boundary of the support. Default value is 1. |
ran.dist.Binomial([n[, p]])
Generator for the binomial distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| n | number | Number of trials. Default value is 100. |
| p | number | Probability 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):with , , and is the probability density function of the standard normal distribution. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| beta | number | Scale parameter. Default value is 1. |
| gamma | number | Shape parameter. Default value is 1. |
ran.dist.Borel(mu)
Generator for the Borel distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Distribution parameter. Default value is 0.5. |
ran.dist.BorelTanner(mu, n)
Generator for the Borel-Tanner distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Distribution parameter. Default value is 0.5. |
| n | number | Number 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:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| L | number | Lower boundary. Default value is 1. |
| H | number | Upper boundary. Default value is 10. |
| alpha | number | Shape parameter. Default value is 1. |
ran.dist.Bradford([c])
Generator for the Bradford distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| c | number | Shape parameter. Default value is 1. |
ran.dist.Burr([c[, k]])
Generator for the Burr (XII) distribution (also known as Singh-Maddala distribution):with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| c | number | First shape parameter. Default value is 1. |
| k | number | Second shape parameter. Default value is 1. |
ran.dist.Categorical([weights[, min]])
Generator for a categorical distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| weights | number[] | Weights for the distribution (doesn't need to be normalized). Default value is an array with a single value of 1. |
| min | number | Lowest value to sample (support starts at this value). Default value is [1, 1, 1]. |
ran.dist.Cauchy([x0[, gamma]])
Generator for the Cauchy distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| x0 | number | Location parameter. Default value is 0. |
| gamma | number | Scale parameter. Default value is 1. |
ran.dist.Chi([k])
Generator for the distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| k | number | Degrees of freedom. If not an integer, is rounded to the nearest integer. Default value is 2. |
ran.dist.Chi2([k])
Generator for the distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| k | number | Degrees 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:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| p | number | First shape parameter. Default value is 1. |
| a | number | Second shape parameter. Default value is 1. |
| b | number | Scale parameter. Default value is 1. |
ran.dist.Degenerate([x0])
Generator for the degenerate distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| x0 | number | Location of the distribution. Default value is 0. |
ran.dist.Delaporte([alpha[, beta[, lambda]]])
Generator for the Delaporte distribution:with . Support: . For , it is the negative binomial, and for 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
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter of the gamma component. Default component is 1. |
| beta | number | Scale parameter of the gamma component. Default value is 1. |
| lambda | number | Mean of the Poisson component. Default value is 1. |
ran.dist.DiscreteUniform([xmin[, xmax]])
Generator for the discrete uniform distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| xmin | number | Lower boundary. If not an integer, it is rounded to the nearest one. Default value is 0. |
| xmax | number | Upper 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):with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| q | number | First shape parameter. Default value is 0.5. |
| beta | number | Second 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):where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 1. |
| beta | number | Rate parameter. Default value is 1. |
ran.dist.DoubleWeibull([lambda[, k]])
Generator for the double Weibull distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Scale parameter. Default value is 1. |
| k | number | Shape parameter. Default value is 1. |
ran.dist.DoublyNoncentralBeta([alpha[, beta[, lambda1[, lambda2]]]])
Generator for the doubly non-central beta distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 1. |
| lambda1 | number | First non-centrality parameter. Default value is 1. |
| lambda2 | number | Second non-centrality parameter. Default value is 1. |
ran.dist.DoublyNoncentralF([d1[, d2[, lambda1[, lambda2]]]])
Generator for the doubly non-central F distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| d1 | number | First degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2. |
| d2 | number | Second degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2. |
| lambda1 | number | First non-centrality parameter. Default value is 1. |
| lambda2 | number | Second non-centrality parameter. Default value is 1. |
ran.dist.DoublyNoncentralT(nu, mu, theta)
Generator for the doubly non-central t distribution:where , and . Support: . Implementation is based on Section 10.4.1.2 in Marc S. Paolella. Intermediate Probability: A Computational Approach. (2007)
Parameters
| Name | Type | Description |
|---|---|---|
| nu | number | Degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 1. |
| mu | number | Location parameter. Default value is 1. |
| theta | number | Shape parameter. Default value is 1. |
ran.dist.Erlang([k[, lambda]])
Generator for the Erlang distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| k | number | Shape parameter. It is rounded to the nearest integer. Default value is 1. |
| lambda | number | Rate parameter. Default value is 1. |
ran.dist.Exponential([lambda])
Generator for the exponential distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Rate parameter. Default value is 1. |
ran.dist.ExponentialLogarithmic([p[, beta]])
Generator for the exponential-logarithmic distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| p | number | Shape parameter. Default value is 0.5. |
| beta | number | Scale parameter. Default value is 1. |
ran.dist.ExponentiatedWeibull([lambda[, k[, alpha]]])
Generator for the exponentiated Weibull distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Scale parameter. Default value is 1. |
| k | number | First shape parameter. Default value is 1. |
| alpha | number | Second shape parameter. Default value is 1. |
ran.dist.F([d1[, d2]])
Generator for the F distribution (or Fisher-Snedecor's F distribution):with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| d1 | number | First degree of freedom. If not an integer, it is rounded to the nearest one. Default value is 2. |
| d2 | number | Second 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:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| d1 | number | First degree of freedom. Default value is 2. |
| d2 | number | Second degree of freedom. Default value is 2. |
ran.dist.FlorySchulz([a])
Generator for the Flory-Schulz distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Shape parameter. Default value is 0.5. |
ran.dist.Frechet([alpha[, s[, m]]])
Generator for the Frechet distribution:with . and , . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 1. |
| s | number | Scale parameter. Default value is 1. |
| m | number | Location parameter. Default value is 0. |
ran.dist.Gamma([alpha[, beta]])
Generator for the gamma distribution using the shape/rate parametrization:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 1. |
| beta | number | Rate parameter. Default value is 1. |
ran.dist.GammaGompertz([b[, s[, beta]]])
Generator for the Gamma/Gompertz distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| b | number | Scale parameter. Default value is 1. |
| s | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 1. |
ran.dist.GeneralizedExponential([a[, b[, c]]])
Generator for the generalized exponential distribution:where . Support> .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | First shape parameter. Default value is 1. |
| b | number | Second shape parameter. Default value is 1. |
| c | number | Third shape parameter. Default value is 1. |
ran.dist.GeneralizedExtremeValue([c])
Generator for the generalized extreme value distribution:with . Support: if , otherwise.
Parameters
| Name | Type | Description |
|---|---|---|
| c | number | Shape parameter. Default value is 2. |
ran.dist.GeneralizedGamma([a[, d[, p]]])
Generator for the generalized gamma distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Scale parameter. Default value is 1. |
| d | number | Shape parameter. Default value is 1. |
| p | number | Shape parameter. Default value is 1. |
ran.dist.GeneralizedHermite([a1[, am[, m]]])
Generator for the generalized Hermite distribution:where , , , and . Support: . It is the distribution of where are Poisson variates with parameters respectively.
Parameters
| Name | Type | Description |
|---|---|---|
| a1 | number | Mean of the first Poisson component. Default value is 1. |
| am | number | Mean of the second Poisson component. Default value is 1. |
| m | number | Multiplier 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:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| s | number | Scale parameter. Default value is 1. |
| c | number | Shape parameter. Default value is 1. |
ran.dist.GeneralizedNormal([mu[, alpha[, beta]]])
Generator for the generalized normal distribution:where and . Support: . It is also a special case of the generalized gamma distribution.
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location paramameter. Default value is 0. |
| alpha | number | Scale parameter. Default value is 1. |
| beta | number | Shape parameter. Default value is 1. |
ran.dist.GeneralizedPareto([mu[, sigma[, xi]]])
Generator for the generalized Pareto distribution:with , and . Support: if , otherwise.
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| sigma | number | Scale parameter. Default value is 1. |
| xi | number | Shape parameter. Default value is 1. |
ran.dist.Geometric(p)
Generator for the geometric distribution (the number of failures before the first success definition):with . Support: . Note that the discrete exponential distribution is also a geometric distribution with rate parameter equal to .
Parameters
| Name | Type | Description |
|---|---|---|
| p | number | Probability of success. Default value is 0.5. |
ran.dist.Gilbrat()
Generator for the Gilbrat's distribution:Support: . Note that this distribution is simply a special case of the log-normal.
ran.dist.Gompertz([eta[, beta]])
Generator for the Gompertz distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| eta | number | Shape parameter. Default value is 1. |
| beta | number | Scale parameter. Default value is 1. |
ran.dist.Gumbel([mu[, beta]])
Generator for the Gumbel distribution:with and , . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| beta | number | Scale parameter. Default value is 1. |
ran.dist.HalfGeneralizedNormal([alpha[, beta]])
Generator for the half generalized normal distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Scale parameter. Default value is 1. |
| beta | number | Shape parameter. Default value is 1. |
ran.dist.HalfLogistic()
Generator for the half-logistic distribution:Support: .
ran.dist.HalfNormal([sigma])
Generator for the half-normal distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| sigma | number | Scale parameter. Default value is 1. |
ran.dist.HeadsMinusTails([n])
Generator for the heads-minus-tails distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| n | number | Half number of trials. Default value is 10. |
ran.dist.Hoyt([q[, omega]])
Generator for the Hoyt distribution (also known as Nakagami-q distribution):where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| q | number | Shape parameter. Default value is 0.5. |
| omega | number | Spread parameter. Default value is 1. |
ran.dist.HyperbolicSecant()
Generator for the hyperbolic secant distribution:Support: .
ran.dist.Hyperexponential([parameters])
Generator for the hyperexponential distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| parameters | Object[] | 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:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| N | number | Total number of elements to sample from. If not an integer, it is rounded to the nearest one. Default value is 10. |
| K | number | Total number of successes. If not an integer, it is rounded to the nearest one. Default value is 5. |
| n | number | If 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 distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| nu | number | Degrees of freedom. Default value is 1. |
ran.dist.InverseGamma([alpha[, beta]])
Generator for the inverse gamma distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 1. |
| beta | number | Scale parameter. Default value is 1. |
ran.dist.InverseGaussian([mu[, lambda]])
Generator for the Wald or inverse Gaussian distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Mean of the distribution. Default value is 1. |
| lambda | number | Shape parameter. Default value is 1. |
ran.dist.InvertedWeibull([c])
Generator for the inverted Weibull distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| c | number | Shape parameter. Default value is 2. |
ran.dist.IrwinHall([n])
Generator for the Irwin-Hall distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| n | number | Number 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 distribution:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| gamma | number | First location parameter. Default value is 0. |
| delta | number | First scale parameter. Default value is 1. |
| lambda | number | Second scale parameter. Default value is 1. |
| xi | number | Second location parameter. Default value is 0. |
ran.dist.JohnsonSU([gamma[, delta[, lambda[, xi]]]])
Generator for Johnson's distribution:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| gamma | number | First location parameter. Default value is 0. |
| delta | number | First scale parameter. Default value is 1. |
| lambda | number | Second scale parameter. Default value is 1. |
| xi | number | Second location parameter. Default value is 0. |
ran.dist.Kolmogorov()
Generator for the Kolmogorov distribution:Support: .
ran.dist.Kumaraswamy([alpha[, beta]])
Generator for the Kumaraswamy distribution (also known as Minimax distribution):with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 1. |
ran.dist.Laplace([mu[, b]])
Generator for the Laplace distribution (also known as double exponential distribution):where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| b | number | Scale parameter. Default value is 1. |
ran.dist.Levy([mu[, c]])
Generator for the Lévy distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| c | number | Scale parameter. Default value is 1. |
ran.dist.Lindley([theta])
Generator for the Lindley distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| theta | number | Shape parameter. Default value is 1. |
ran.dist.Logarithmic([a[, b]])
Generator for the (continuous) logarithmic distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Lower boundary of the distribution. Default value is 1. |
| b | number | Upper boundary of the distribution. Default value is 2. |
ran.dist.LogCauchy([mu[, sigma]])
Generator for the log-Cauchy distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| sigma | number | Scale parameter. Default value is 1. |
ran.dist.LogGamma([alpha[, beta[, mu]]])
Generator for the log-gamma distribution using the shape/rate parametrization:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 1. |
| beta | number | Rate parameter. Default value is 1. |
| mu | number | Location parameter. Default value is 0. |
ran.dist.Logistic([mu[, s]])
Generator for the logistic distribution:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| s | number | Scale parameter. Default value is 1. |
ran.dist.LogisticExponential([lambda[, kappa]])
Generator for the logistic-exponential distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Scale parameter. Default value is 1. |
| kappa | number | Shape parameter. Default value is 1. |
ran.dist.LogitNormal([mu[, sigma]])
Generator for the logit-normal distribution:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| sigma | number | Scale parameter. Default value is 1. |
ran.dist.LogLaplace([mu[, b]])
Generator for the log-Laplace distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| b | number | Scale parameter. Default value is 1. |
ran.dist.LogLogistic([alpha[, beta]])
Generator for the log-logistic distribution (also known as Fisk distribution):with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Scale parameter. Default value is 1. |
| beta | number | Shape parameter. Default value is 1. |
ran.dist.LogNormal([mu[, sigma]])
Generator for the log-normal distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| sigma | number | Scale parameter. Default value is 1. |
ran.dist.LogSeries([p])
Generator for the log-series distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| p | number | Distribution parameter. Default value is 0.5. |
ran.dist.Lomax([lambda[, alpha]])
Generator for the Lomax distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Scale parameter. Default value is 1. |
| alpha | number | Shape parameter. Default value is 1. |
ran.dist.Makeham([alpha[, beta[, lambda]]])
Generator for the Makeham distribution (also known as Gompertz-Makeham distribution):with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 1. |
| beta | number | Rate parameter. Default value is 1. |
| lambda | number | Scale parameter. Default value is 1. |
ran.dist.MaxwellBoltzmann([a])
Generator for the Maxwell-Boltzmann distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Scale parameter. Default value is 1. |
ran.dist.Mielke([k[, s]])
Generator for the Mielke distribution:with . Support: . It can be viewed as a re-parametrization of the Dagum distribution.
Parameters
| Name | Type | Description |
|---|---|---|
| k | number | First shape parameter. Default value is 2. |
| s | number | Second shape parameter. Default value is 1. |
ran.dist.Moyal([mu[, sigma]])
Generator for the Moyal distribution:where , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| sigma | number | Scale parameter. Default value is 1. |
ran.dist.Muth([alpha])
Generator for the Muth distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | Shape parameter. Default value is 0.5. |
ran.dist.Nakagami([m[, omega]])
Generator for the Nakagami distribution:where , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| m | number | Shape parameter. Default value is 1. |
| omega | number | Spread 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):with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| r | number | Number of failures until the experiment is stopped. If not an integer, it is rounded to the nearest integer. Default value is 10. |
| p | number | Probability of success. Default value is 0.5. |
ran.dist.NegativeHypergeometric([N[, K[, r]]])
Generator for the negative hypergeometric distribution:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| N | number | Total number of elements to sample from. If not an integer, it is rounded to the nearest one. Default value is 10. |
| K | number | Total number of successes. If not an integer, it is rounded to the nearest one. Default value is 5. |
| r | number | Total 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:where and denotes the Stirling number of the second kind. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Mean of the number of clusters. Default value is 1. |
| phi | number | Mean of the cluster size. Default value is 1. |
ran.dist.NoncentralBeta([alpha[, beta[, lambda]]])
Generator for the non-central beta distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| alpha | number | First shape parameter. Default value is 1. |
| beta | number | Second shape parameter. Default value is 1. |
| lambda | number | Non-centrality parameter. Default value is 1. |
ran.dist.NoncentralChi([k[, lambda]])
Generator for the non-central distribution:with , and is the modified Bessel function of the first kind with order . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| k | number | Degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2. |
| lambda | number | Non-centrality parameter. Default value is 1. |
ran.dist.NoncentralChi2([k[, lambda]])
Generator for the non-central distribution:with , and is the modified Bessel function of the first kind with order . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| k | number | Degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 2. |
| lambda | number | Non-centrality parameter. Default value is 1. |
ran.dist.NoncentralF([d1[, d2[, lambda]]])
Generator for the non-central F distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| d1 | number | First degree of freedom. If not an integer, it is rounded to the nearest one. Default value is 2. |
| d2 | number | Second degree of freedom. If not an integer, it is rounded to the nearest one. Default value is 2. |
| lambda | number | Non-centrality parameter. Default value is 1. |
ran.dist.NoncentralT([nu[, mu]])
Generator for the non-central t distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| nu | number | Degrees of freedom. If not an integer, it is rounded to the nearest one. Default value is 1. |
| mu | number | Non-centrality parameter. Default value is 1. |
ran.dist.Normal([mu[, sigma]])
Generator for the normal distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter (mean). Default value is 0. |
| sigma | number | Squared scale parameter (variance). Default value is 1. |
ran.dist.Pareto([xmin[, alpha]])
Generator for the Pareto distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| xmin | number | Scale parameter. Default value is 1. |
| alpha | number | Shape parameter. Default value is 1. |
ran.dist.PERT([a[, b[, c]]])
Generator for the PERT distribution:where , , , and is the beta function. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Lower boundary of the support. Default value is 0. |
| b | number | Mode of the distribution. Default value is 0.5. |
| c | number | Upper boundary of the support. Default value is 1. |
ran.dist.Poisson([lambda])
Generator for the Poisson distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Mean 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):where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Mean of the Poisson component. Default value is 1. |
| theta | number | Parameter 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):with . Support: . It is a special case of the Kumaraswamy distribution.
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | One plus the exponent of the distribution. Default value is 1. |
ran.dist.QExponential([q[, lambda]])
Generator for the q-exponential distribution:where , and denotes the q-exponential function. Support: if , otherwise .
Parameters
| Name | Type | Description |
|---|---|---|
| q | number | Shape parameter. Default value is 1.5. |
| lambda | number | Rate parameter. Default value is 1. |
ran.dist.R([c])
Generator for the R distribution:where . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| c | number | Shape parameter. Default value is 1. |
ran.dist.Rademacher()
Generator for the Rademacher distribution:Support: .
ran.dist.RaisedCosine([mu[, s]])
Generator for the raised cosine distribution:where and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location paramter. Default value is 0. |
| s | number | Scale parameter. Default value is 1. |
ran.dist.Rayleigh([sigma])
Generator for the Rayleigh distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| sigma | number | Scale parameter. Default value is 1. |
ran.dist.Reciprocal([a[, b]])
Generator for the reciprocal distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Lower boundary of the support. Default value is 1. |
| b | number | Upper boundary of the support. Default value is 2. |
ran.dist.ReciprocalInverseGaussian([mu[, lambda]])
Generator for the reciprocal inverse Gaussian distribution (RIG):with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Mean of the inverse Gaussian distribution. Default value is 1. |
| lambda | number | Shape parameter. Default value is 1. |
ran.dist.Rice([nu[, sigma]])
Generator for the Rice distribution:with and is the modified Bessel function of the first kind with order zero. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| nu | number | First shape parameter. Default value is 1. |
| sigma | number | Second shape parameter. Default value is 1. |
ran.dist.ShiftedLogLogistic([mu[, sigma[, xi]]])
Generator for the shifted log-logistic distribution:with , and . Support: if , if , otherwise.
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Location parameter. Default value is 0. |
| sigma | number | Scale parameter. Default value is 1. |
| xi | number | Shape parameter. Default value is 1. |
ran.dist.Skellam([mu1[, mu2]])
Generator for the Skellam distribution:with and is the modified Bessel function of the first kind with order . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu1 | number | Mean of the first Poisson distribution. Default value is 1. |
| mu2 | number | Mean of the second Poisson distribution. Default value is 1. |
ran.dist.SkewNormal([xi[, omega[, alpha]]])
Generator for the skew normal distribution:where , and , denote the probability density and cumulative distribution functions of the standard normal distribution. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| xi | number | Location parameter. Default value is 0. |
| omega | number | Scale parameter. Default value is 1. |
| alpha | number | Shape parameter. Default value is 1. |
ran.dist.Slash()
Generator for the slash distribution:where is the probability density function of the standard normal distribution. Support: .
ran.dist.Soliton([N])
Generator for the (ideal) soliton distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| N | number | Number 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:with and is the beta function. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| nu | number | Degrees of freedom. Default value is 1. |
ran.dist.StudentZ([n])
Generator for Student's Z distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| n | number | Degrees of freedom. Default value is 2. |
ran.dist.Trapezoidal([a[, b[, c[, d]]]])
Generator for the trapezoidal distribution:where , , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Lower bound of the support. Default value is 0. |
| b | number | Start of the level part. Default value is 0.33. |
| c | number | End of the level part. Default value is 0.67. |
| d | number | Upper bound of the support. Default value is 1. |
ran.dist.Triangular([a[, b[, c]]])
Generator for the asymmetric triangular distribution:with , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Lower bound of the support. Default value is 0. |
| b | number | Upper bound of the support. Default value is 1. |
| c | number | Mode of the distribution. Default value is 0.5. |
ran.dist.TruncatedNormal([mu[, sigma[, a[, b]]]])
Generator for the truncated normal distribution:where and . The functions and denote the probability density and cumulative distribution functions of the normal distribution. Finally, , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| mu | number | Mean of the underlying normal distribution. Default value is 0. |
| sigma | number | Variance of the underlying normal distribution. Default value is 1. |
| a | number | Lower boundary of the support. Default value is 0. |
| b | number | Upper boundary of the support. Default value is 1. |
ran.dist.TukeyLambda([lambda])
Generator for the Tukey lambda distribution:where and . Support: if , otherwise .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Shape parameter. Default value is 1.5. |
ran.dist.Uniform([xmin[, xmax]])
Generator for the continuous uniform distribution:with and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| xmin | number | Lower boundary. Default value is 0. |
| xmax | number | Upper boundary. Default value is 1. |
ran.dist.UniformRatio()
Generator for the uniform ratio distribution:Support: .
ran.dist.UQuadratic([a[, b]])
Generator for the u-quadratic distribution:where , , and . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| a | number | Lower bound of the support. Default value is 0. |
| b | number | Upper bound of the support. Default value is 1. |
ran.dist.VonMises([kappa])
Generator for the von Mises distribution:with . Support: . Note that originally this distribution is periodic and therefore it is defined over , but (without the loss of general usage) this implementation still does limit the support on the bounded interval .
Parameters
| Name | Type | Description |
|---|---|---|
| kappa | number | Shape parameter. Default value is 1. |
ran.dist.Weibull([lambda[, k]])
Generator for the Weibull distribution:with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| lambda | number | Scale parameter. Default value is 1. |
| k | number | Shape parameter. Default value is 1. |
ran.dist.Wigner([R])
Generator for Wigner distribution (also known as semicircle distribution):with . Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| R | number | Radius of the distribution. Default value is 1. |
ran.dist.YuleSimon([rho])
Generator for the Yule-Simon distribution:with and is the beta function. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| rho | number | Shape parameter. Default value is 1. |
ran.dist.Zeta([s])
Generator for the zeta distribution:with and is the Riemann zeta function. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| s | number | Exponent of the distribution. Default value is 3. |
ran.dist.Zipf([s[, N]])
Generator for the Zipf distribution:with , and denotes the generalized harmonic number. Support: .
Parameters
| Name | Type | Description |
|---|---|---|
| s | number | Exponent of the distribution. Default value is 1. |
| N | number | Number 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
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate geometric mean for. |
Returns
numberundefinedGemoetric mean of the values if there are any, undefined otherwise.
Examples
ran.location.geometricMean([])
// => undefined
ran.location.geometricMean([1, 2, 3])
// => 1.8171205928321394ran.location.harmonicMean(values)
Calculates the harmonic mean of an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate harmonic mean for. |
Returns
numberundefinedHarmonic 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.6363636363636365ran.location.mean(values)
Calculates the arithmetic mean of an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate mean for. |
Returns
numberundefinedMean of the values if there are any, undefined otherwise.
Examples
ran.location.mean([])
// => undefined
ran.location.mean([1, 2, 3])
// => 2ran.location.median(values)
Calculates the median of a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate median for. |
Returns
numberMedian of the values if there are any, undefined otherwise.
Examples
ran.location.median([])
// => undefined
ran.location.median([1, 2, 3, 4])
// => 2.5ran.location.midrange(values)
Calculates the mid-range for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate mid-range for. |
Returns
numberundefinedThe mid-range of the values if there is any, undefined otherwise.
Examples
ran.location.midrange([])
// => undefined
ran.location.midrange([0, 0, 0, 1, 2])
// => 1ran.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
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate mode for. |
Returns
numbernumber[]undefinedThe 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.5ran.location.trimean(values)
Calculates the trimean for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate trimean for. |
Returns
numberundefinedThe trimean of the values if there is any, undefined otherwise.
Examples
ran.location.trimean([])
// => undefined
ran.location.trimean([1, 1, 1, 2, 3])
// => 1.25ran.shape.kurtosis(values)
Calculates the sample excess kurtosis which is unbiased for the normal distribution.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate kurtosis for. |
Returns
numberundefinedThe 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.3333333333333326ran.shape.moment(values, k[, c])
Calculates the k-th raw moment for a sample of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate moment for. |
| k | number | Order of the moment. |
| c | number | Value to shift the distribution by before calculating the moment. |
Returns
numberundefinedThe 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.666666666666667ran.shape.quantile(values, p)
Calculates the quantile at 0 < p < 1 using the R-7 algorithm.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate quantile for. |
| p | number | Value to calculate quantile at. |
Returns
numberundefinedThe quantile of the sample if there is any, undefined otherwise.
ran.shape.rank(values)
Calculates the fractional rank for an array of values.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate ranks for. |
Returns
numberundefinedThe 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
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate skewness for. |
Returns
numberundefinedThe 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])
// => -2ran.shape.yule(values)
Calculates Yule's coefficient which is a measure of skewness based on quantiles.
Parameters
| Name | Type | Description |
|---|---|---|
| values | number[] | Array of values to calculate Yule's coefficient for. |
Returns
numberundefinedYule'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])
// => -1ran.test.bartlett(dataSets[, alpha])
Calculates the Bartlett statistics for multiple data sets.
Parameters
| Name | Type | Description |
|---|---|---|
| dataSets | Array[] | Array containing the data sets. |
| alpha | number | Confidence level. |
Returns
ObjectObject containing the test statistics (chi2) and whether the data sets passed the null hypothesis that their variances are the same.
Throws
ErrorIf the number of data sets is less than 2.
ErrorIf 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
| Name | Type | Description |
|---|---|---|
| dataSets | Array[] | Array containing the data sets. |
| alpha | number | Confidence level. |
Returns
ObjectObject containing the test statistics (W) and whether the data sets passed the null hypothesis that their variances are the same.
Throws
ErrorIf the number of data sets is less than 2.
ErrorIf 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
| Name | Type | Description |
|---|---|---|
| dataSets | Array[] | Array containing the two data sets. |
| alpha | number | Confidence level. |
Returns
ObjectObject containing the test statistics and whether the data sets passed the null hypothesis that they are statistically independent.
Throws
ErrorIf the number of data sets is less than 2.
ErrorIf the data sets have different sample size.
ErrorIf 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
| Name | Type | Description |
|---|---|---|
| dataSets | Array[] | Array containing the data sets. |
| alpha | number | Confidence level. |
Returns
ObjectObject containing the test statistics (W) and whether the data sets passed the null hypothesis that their variances are the same.
Throws
ErrorIf the number of data sets is less than 2.
ErrorIf 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
| Name | Type | Description |
|---|---|---|
| dataSets | Array[] | Array containing the two data sets. |
| alpha | number | Confidence level. |
Returns
ObjectObject 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
ErrorIf 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 }