Computes the arithmetic mean of the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error. mean()
is an alias of this method.Formula:
Parameters:
(string or array) data (required)
Scales of measure:
interval, metricUsage:
var mean = stats.arithmeticMean([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
4.69230…
Computes the cubic mean of the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Formula:
Parameters:
(string or array) data (required)
Scales of measure:
interval, metricUsage:
var mean = stats.cubicMean([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
6.28600…
Computes the Gastwirth-Cohen mean of the values in a dataset
data
that can be either the name of a column (string) or an array of values. The Gastwirth-Cohen mean is defined as the weighted mean of three quantils:- the
lambda
-weightedalpha
quantil - the
(1 - alpha)
-quantil and - the
(1 - 2 * lambda)
-weighted median
alpha
and lambda
must be within the range of [0, 0.5]
. If the scale of measure of the column given by data
is not ordinal or of higher order or if alpha
or lambda
are outside of the range of [0, 0.5]
, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var mean = stats.gastwirthCohenMean([1, 3, 7, 4, 12, 4, 6, 7, 1, 2], { alpha: 0.3, lambda: 0.1 });
Returns:
4.1
Computes the geometric mean of the values in a dataset
data
that can be either the name of a column (string) or an array of values. If any non-positive values are supplied, this method will return undefined
. If the scale of measure of the column given by data
is not metric, it will return undefined
and throw an error.Formula:
Parameters:
(string or array) data (required)
Scales of measure:
metricUsage:
var mean = stats.geometricMean([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
var meanWithInvalids = stats.geometricMean([0, 3, -12, 7, 9, 4, 1]);
Returns:
mean: 3.74447…
meanWithInvalids: undefined
Computes the harmonic mean of the values in a dataset
data
that can be either the name of a column (string) or an array of values. Returns 0
if any of the values are also 0
. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Formula:
Parameters:
(string or array) data (required)
Scales of measure:
metricUsage:
var mean = stats.harmonicMean([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
2.82901…
Retrieves the median of a dataset
data
that can be either the name of a column (string) or an array of values.Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var median = stats.median([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
4
Computes the mid-range of a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
interval, metricUsage:
var midRange = stats.midRange([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
6.5
Retrieves the most frequent value in a dataset
data
that can be either the name of a column (string) or an array of values. If there are two or more most common values of equal frequency, an array with these values will be returned.Parameters:
(string or array) data (required)
Scales of measure:
nominal, ordinal, interval, metricUsage:
var mode = stats.mode([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
[4, 7]
Computes the root mean square of the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Formula:
Parameters:
(string or array) data (required)
Scales of measure:
interval, metricUsage:
var mean = stats.rootMeanSquare([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
5.54006…
Computes the Winsorised (truncated) mean of the values in a dataset
data
that can be either the name of a column (string) or an array of values. Note, that for every truncated value of the sorted list, the now most extreme value will be repeated in its place, e.g. in a 10% truncated list of twenty values both the originally third and the 18th value in order will be repeated twice in order to replace the truncated first, second and 19th and 20th values, respectively. It’s commonly used to discard outliers that are within the outermost percentage
per cent of values on either end of the full range. percentage
must be an integer or floating point number within the range of [0, 0.5]
. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
(integer or float) percentage (optional, default: 0.2)
Scales of measure:
interval, metricUsage:
var mean = stats.winsorisedMean([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2], 0.33);
Returns:
4.38461…
The coefficient of variation is a relative parameter of dispersion that expresses the standard deviation relative to the expected value of a statistical variable. This allows for comparison of variables with significantly diverse expected values. Thus, it is similar to the index of dispersion. The expected value can either be supplied as an additional input parameter or will be substituted by the arithmetic mean. If the scale of measure of the column given by
data
is not interval or of higher order, it will return undefined
and throw an error.Formulas:
with
Parameters:
(string or array) data (required)
(integer or float) expectedValue (optional)
Scales of measure:
interval, metricUsage:
var coeffVar = stats.coefficientOfVariation([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
0.65330…
Counts the number of values in a dataset
data
that can be either the name of a column (string) or an array of values that smaller or equal to boundary
. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
(integer or float) boundary (optional)
Scales of measure:
ordinal, interval, metricUsage:
var frequency = stats.cumulativeFrequency([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2], 6);
Returns:
9
Sorts the values in a dataset
data
that can be either the name of a column (string) or an array of values in descending order and returns them with their absolute and relative (in the range of 0
and 1
) frequencies.Parameters:
(string or array) data (required)
Scales of measure:
nominal, ordinal, interval, metricUsage:
var frequencies = stats.frequencies(["male", "female", "male", "male", "female", "female", "indeterminate", "female"]);
Returns:
[
{ value: "female", absolute: 4, relative: 0.5 },
{ value: "male", absolute: 3, relative: 0.375 },
{ value: "indeterminate", absolute: 1, relative: 0.125 }
]
Computes the geometric standard deviation of the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
interval, metricUsage:
var stdDev = stats.geometricStandardDeviation([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
2.05493…
The index of dispersion is a relative parameter of dispersion that expresses the variance relative to the expected value of a statistical variable. This allows for comparison of variables with significantly diverse expected values. Thus, it is similar to the coefficient of variation. The expected value can either be supplied as an additional input parameter or will be substituted by the arithmetic mean. If the scale of measure of the column given by
data
is not interval or of higher order, it will return undefined
and throw an error.Formulas:
with
Parameters:
(string or array) data (required)
(integer or float) expectedValue (optional)
Scales of measure:
interval, metricUsage:
var indexDisp = stats.indexOfDispersion([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
2.00273…
Computes the interquartile range of a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
interval, metricUsage:
var interQuartileRange = stats.interQuartileRange([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
4
Finds the largest among the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var min = stats.maximum([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
12
Computes the median absolute deviation of the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
interval, metricUsage:
var medDev = stats.medianAbsoluteDeviation([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
2
Finds the smallest among the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var min = stats.minimum([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
1
Computes the quantiles of the values in a dataset
data
that can be either the name of a column (string) or an array of values. The percentage
should be given as an integer or floating point number between 0
and 1
. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
(integer or float) percentage (required)
Scales of measure:
ordinal, interval, metricUsage:
var quantile = stats.quantile([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2], 0.33);
Returns:
3
Computes the quartiles of the values in a dataset
data
that can be either the name of a column (string) or an array of values and returns them as an array with the lower quartile at the 0th index and the higher quartile at the 1st index. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var mode = stats.quartiles([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
[3, 7]
Computes the range of the values in a dataset
data
that can be either the name of a column (string) or an array of values, defined as the difference of their maximum and their minimum. If the scale of measure of the column given by data
is nominal, it will retrieve an array of all the unique values in the dataset instead. Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var range = stats.range([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
11
Computes the standard deviation of the values in a dataset
data
that can be either the name of a column (string) or an array of values. By default, the arithmetic mean is computed for and Bessel’s correction is applied. This is the best option if the true arithmetic mean within the population is a priori unknown and can only be approximated by the arithmetic mean of the sample. If corrected
is set to false
, Bessel’s correction will not be applied, effectively computing the population variance with an unknown arithmetic mean. If corrected
is set to an integer or a floating point number, this will be used as the true mean and Bessel’s correction will not be applied. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Formulas:
with
Parameters:
(string or array) data (required)
(boolean, integer or float) corrected (optional, default: true)
Scales of measure:
interval, metricUsage:
var variance = stats.standardDeviation([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
3.06552…
Computes the variance of the values in a dataset
data
that can be either the name of a column (string) or an array of values. By default, the arithmetic mean is computed for and Bessel’s correction is applied. This is the best option if the true arithmetic mean within the population is a priori unknown and can only be approximated by the arithmetic mean of the sample. In that case, the numerically stable Welford’s method is used which yields a correct result even for very large datasets and very large numbers. If corrected
is set to false
, Bessel’s correction will not be applied, effectively computing the population variance with an unknown arithmetic mean. If corrected
is set to an integer or a floating point number, this will be used as the true mean and Bessel’s correction will not be applied. If the scale of measure of the column given by data
is not interval or of higher order, it will return undefined
and throw an error.Formulas:
with
Parameters:
(string or array) data (required)
(boolean, integer or float) corrected (optional, default: true)
Scales of measure:
interval, metricUsage:
var variance = stats.variance([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
9.39743…
Computes the excess kurtosis of the values in a dataset
data
that can be either the name of a column (string) or an array of values. This measure was introduced to compare the shape of a distribution to that of the normal distribution. It is defined as the kurtosis and can make three basic descriptions:- (mesokurtic): the bell shape of the normal distribution
- (leptokurtic): a more slender and steep shape
- (platykurtic): a more flat and wide shape
data
is not ordinal or of higher order, it will return undefined
and throw an error.Formula:
Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var excess = stats.excessKurtosis([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
-0.05486…
Computes the kurtosis of the values in a dataset
data
that can be either the name of a column (string) or an array of values. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Formula:
Parameters:
(string or array) data (required)
Scales of measure:
ordinal, interval, metricUsage:
var kurtosis = stats.kurtosis([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
2.94513…
Computes the sample skewness of the values in a dataset
data
that can be either the name of a column (string) or an array of values. There are several definitions of skewness, however this toolkit uses the sample skewness if populationSkewness
is set to false
and the adjusted Fisher-Pearson standardised moment coefficient for the sample skewness if it’s set to true
. If the scale of measure of the column given by data
is not ordinal or of higher order, it will return undefined
and throw an error.Formulas:
Sample skewness
Sample population skewness
Parameters:
(string or array) data (required)
(boolean) populationSkewness (optional, default: false)
Scales of measure:
ordinal, interval, metricUsage:
var skewness = stats.skewness([1, 3, 7, 4, 12, 4, 4, 7, 3, 6, 7, 1, 2]);
Returns:
1.02037…