Computes the beta function of two values and with . If both variables have an integer value, factorials instead of the gamma function will be computed since the gamma function, even in its more exact Spouge’s approximation, will still introdue some error.
Formula:
Parameters:
(integer or float) a (required)
(integer or float) b (required)
Usage:
var beta = stats.beta(4.2, 3);
Returns:
0.01477…
Computes the binomial coefficient for two integers
n
and k
. A common way to think of the binomial coefficient is that it gives the number of ways to choose k
out of n
objects regardless of order.Formulas:
with
Parameters:
(integer) n (required)
(integer) k (required)
Usage:
var nChooseK = stats.binomialCoefficient(7, 3);
Returns:
35
Retrieves or computes the
n
th factorial. If n
is a floating point number, the result of the gamma() function will be returned.Formula:
Parameters:
(integer or float) n (required)
Usage:
var factorial = stats.factorial(16);
Returns:
20922789888000
Computes the gamma function for a given
n
. As this is can be an expensive operation, different methods can be applied to approximate the actual value. Setting moreExact
to true
will use Spouge’s approximation (with by default, however, you can define that constant upon initialisation), default is to use the Stirling-Nemes approximation.Formulas:
Stirling-Nemes approximation:
Spouge’s approximation:
with
and the constant a (can be defined on initialisation)
Parameters:
(integer or float) n (required)
(boolean) moreExact (optional, default: false)
Usage:
var gamma = stats.gamma(4.32, true);
Returns:
9.09595…
Computes the lower incomplete beta function of two values and with over the interval for . This method is an implementation of the function's continued fraction representation, which usually converges fast. The number of iterations can be adjusted by declaring the incompleteBetaIterations setting upon initialisation. For , its result is equal to that of the beta function for and .
Formula:
Parameters:
(integer or float) x (required)
(integer or float) a (required)
(integer or float) b (required)
Usage:
var incompleteBeta = stats.incompleteBeta(0.75, 4.2, 3);
Returns:
0.01205…
Computes the lower incomplete gamma function of two values and with over the interval . This method is an implementation of the function's continued fraction representation, which usually converges fast. The number of iterations can be adjusted by declaring the incompleteGammaIterations setting upon initialisation.
Formula:
Parameters:
(integer or float) s (required)
(integer or float) x (required)
Usage:
var incompleteGamma = stats.incompleteGamma(0.75, 4.2);
Returns:
1.21543…
Computes the product of all the values in a dataset
data
that can be either the name of a column (string) or an array of values. Elements that are not integer, a floating point number or a number string will be ignored.Parameters:
(string or array) data (required)
Usage:
var product = stats.product([1, 3, 7, 4, 12, true, 4, "a", 3, 6, 7, 1, 2]);
Returns:
1016064 /* (true and "a" will be ignored) */
Computes the regularised beta function of two values and with over the interval for . It corresponds to the ratio of the lower incomplete beta function and the complete beta function , which will be computed if any of
a
or b
is not an integer. Otherwise, it will compute the value by expanding the series representation with precision defined by epsilon.Formulas:
for integers a and b:
Parameters:
(integer or float) x (required)
(integer or float) a (required)
(integer or float) b (required)
Usage:
var regularisedBeta = stats.regularisedBeta(0.75, 4.2, 3);
Returns:
0.27207…
Computes the regularised gamma function of two values and with over the interval . It corresponds to the ratio of the lower incomplete gamma function and the complete gamma function .
Formula:
Parameters:
(integer or float) s (required)
(integer or float) x (required)
Usage:
var regularisedGamma = stats.regularisedGamma(0.75, 4.2);
Returns:
0.99185…
Computes the sum of all the values in a dataset
data
that can be either the name of a column (string) or an array of values. Elements that are not integer, a floating point number or a number string will be ignored. Consider using sumExact() for floating point numbers, as JavaScript might compute wrong results.Parameters:
(string or array) data (required)
Usage:
var sum = stats.sum([12, 9, 14, "a", 22, 0, -12, true]);
Returns:
45 /* ("a" and true will be ignored) */
Computes the sum of all the values in a dataset
data
that can be either the name of a column (string) or an array of values. Sums of floating point numbers will be computed correctly, whereas sum() might deliver incorrect results due to how JavaScript handles these numbers. This method uses Kahan’s algorithm which diminishes the error to floating point precision that is negligable under most if not all conditions. Elements that are not integer, a floating point number or a number string will be ignored.Parameters:
(string or array) data (required)
Usage:
var sumExact = stats.sumExact([12.3, 9.0, 14.2, "a", 22.98, 0, -12.0000003, true]);
Returns:
46.4799997 /* ("a" and true will be ignored) */