Statistics

Collection of statistical functions.

Methods

mean

mean(values: number[])

Calculates the average for given array of values.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

// Calculates the mean for a number of given values:
Statistics.mean([1, 2, 3, 4, 5, 6, 7, 8, 9, 25]) // => 7 (Calculates mean for values 1, 2, 3, 4, 5, 6, 7, 8, 9 and 25)

mode

mode(values: number[])

Calculates the most frequent occurring value(s) within a given array. Returns a single value. In the case of multiple modes, this will return the lowest value.

Parameters

values number[]

The array of values on which the mode is deducted.

Return type

number

Examples

modes

Calculates the most frequent occurring value(s) within a given array. Returns an array.

Parameters

values number[]

The array of values on which the mode is deducted.

Return type

number[]

Examples

median

Returns the median, or the number in the middle of the given array.

Parameters

values number[]

The array of values on which the median is calculated.

Return type

number

Examples

slope

Calculates the slope for a given number of points. If the x-values are omitted, the assumption is that all x-values have corresponding consecutive y-values [1 .. nr of x-values]. X-values may be numeric or of type Year ("YYYY") or YearMonth ("YYYY-MM").

Parameters

knownYvalues number[]

The array of values on which the calculation is made.

knownXvalues number[]

(optional) The x-values array. If omitted, the x-values are generated as 1,2,3...n for the number of y-values

Return type

number

Examples

intercept

Calculates the intercept (the value at the intersection of the y axis) of the linear regression line through a supplied set of x-values. If the x-values are omitted, the assumption is that all x-values have corresponding consecutive y-values [1 .. nr of x-values]. X-values may be numeric or of type Year ("YYYY") or YearMonth ("YYYY-MM")

Parameters

knownYvalues number[]

The array of values on which the calculation is made.

knownXvalues number[]

(optional) The x-values array. If omitted, the x-values are generated as 1,2,3...n for the number of y-values. X-values may be numeric or of type Year ("YYYY") or YearMonth ("YYYY - MM")

Return type

number

Examples

rsq

Returns the square of the Pearson product moment correlation coefficient. If the x-values are omitted, the assumption is that all x-values have corresponding consecutive y-values [1 .. nr of x-values]. X-values may be numeric or of type Year ("YYYY") or YearMonth ("YYYY-MM")

Parameters

knownYvalues number[]

The array of values on which the calculation is made.

knownXvalues number[]

(optional) The x-values array. If omitted, the x-values are generated as 1,2,3...n for the number of y-values. X-values may be numeric or of type Year ("YYYY") or YearMonth ("YYYY - MM")

Return type

number

Examples

varP

Calculates variance based on the entire population and assumes that its arguments are the entire population. If your data represents a sample of the population, then compute the variance by using VarS.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

varS

Calculates variance based on a sample and assumes that its arguments are a sample of the population. If your data represents the entire population, then compute the variance by using VarP.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

stdDevP

Returns the standard deviation based on the entire population given as arguments.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

stdDevS

Returns the standard deviation based on a sample list of values.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

stdErrorP

Returns the standard error based on the entire population given as arguments.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

stdErrorS

Returns the standard error based on a sample list of values.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

normalRandom

Returns a random number from a normal distribution.

Parameters

mean number

The mean or expectation of the distribution.

stdDev number

The standard deviation of the distribution.

Return type

number

Examples

normalDistribution

Returns [nrOfValues] random numbers from a normal distribution.

Parameters

mean number

The mean or expectation of the distribution.

stdDev number

The standard deviation of the distribution.

nrOfValues number

The number of random numbers returned.

Return type

number[]

Examples

gammaRandom

Returns a random number from a gamma distribution.

Parameters

alpha number

The shape of the distribution. Should be a positive number.

beta number

The rate of the distribution. Should be a positive integer value.

Return type

number

Examples

gammaDistribution

Returns [nrOfValues] random numbers from a gamma distribution.

Parameters

alpha number

The shape of the distribution. Should be a positive number.

beta number

The rate of the distribution. Should be a positive integer value.

nrOfValues number

The number of random numbers returned.

Return type

number[]

Examples

meanAbsDev

Returns the Mean Absolute Deviation.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

medianAbsDev

Returns the Median Absolute Deviation.

Parameters

values number[]

The array of values on which the calculation is made.

Return type

number

Examples

findGaps

Returns missing values in an array. Values could be of type number or YearMonth strings

Parameters

values T[]

The array of values in which we look for missing values.

Return type

T[]

Examples

fillGaps

Adds the missing values to an array. Values could be of type number or YearMonth strings

Parameters

values T[]

The array of values in which we look for missing values.

Return type

T[]

Examples

percentile

Returns the value at the given percentile in a sorted array.

Parameters

values number[]

The array of values. Must be sorted.

percentile number

The percentile to find the value for. Must be a number between 0 and 1.

Return type

number

Examples

Last updated