statistics v0.5.0 Statistics

Descriptive statistics functions

Link to this section Summary

Functions

Calculate the the Pearson product-moment correlation coefficient of two lists

Calculate the covariance of two lists

Calculate the geometric mean of a list

Calculates the harmonic mean from a list

Get a frequency count of the values in a list

Calculate the inter-quartile range

Computes the kurtosis (Fisher) of a list

Get the maximum value from a list

Calculate the mean from a list of numbers

Get the median value from a list

Get the minimum value from a list

Get the most frequently occuring value

Calculates the nth moment about the mean for a sample

Get the nth percentile cutoff from a list

Get the quartile cutoff value from a list

Get range of data

Computes the skewness of a data set

Calculate the standard deviation of a list

Sum the contents of a list

Calculate the trimmed mean of a list

Calculate variance from a list of numbers

Calculate a standard z score for each item in a list

Link to this section Functions

Link to this function correlation(x, y)
correlation(list(), list()) :: number()

Calculate the the Pearson product-moment correlation coefficient of two lists.

The two lists are presumed to represent matched pairs of observations, the x and y of a simple regression.

Examples

iex> Statistics.correlation([1,2,3,4], [1,3,5,6])
0.9897782665572894
Link to this function covariance(x, y)
covariance(list(), list()) :: number()

Calculate the covariance of two lists.

Covariance is a measure of how much two random variables change together. The two lists are presumed to represent matched pairs of observations, such as the x and y of a simple regression.

Examples

iex> Statistics.covariance([1,2,3,2,1], [1,4,5.2,7,99])
-17.89
Link to this function geometric_mean(list)
geometric_mean(list()) :: number()

Calculate the geometric mean of a list

Geometric mean is the nth root of the product of n values

Examples

iex> Statistics.geometric_mean([])
nil
iex> Statistics.geometric_mean([1,2,3])
1.8171205928321397
Link to this function harmonic_mean(list)
harmonic_mean(list()) :: number()

Calculates the harmonic mean from a list

Harmonic mean is the number of values divided by the sum of the reciprocal of all the values.

Examples

iex> Statistics.harmonic_mean([])
nil
iex> Statistics.harmonic_mean([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
4.5204836768674568
Link to this function hist(list)
hist(list()) :: map()

Get a frequency count of the values in a list

Examples

iex> Statistics.hist([])
nil
iex> Statistics.hist([1,2,3,2,4,5,2,5,1,2,5,5])
%{1 => 2, 2 => 4, 3 => 1, 4 => 1, 5 => 4}
Link to this function iqr(list)
iqr(list()) :: number()

Calculate the inter-quartile range

Examples

iex> Statistics.iqr([])
nil
iex> Statistics.iqr([1,2,3,4,5,6,7,8,9])
4
Link to this function kurtosis(list)
kurtosis(list()) :: number()

Computes the kurtosis (Fisher) of a list.

Kurtosis is the fourth central moment divided by the square of the variance.

Examples

iex> Statistics.kurtosis([])
nil
iex> Statistics.kurtosis([1,2,3,2,1])
-1.1530612244897964
Link to this function max(list)
max(list()) :: number()

Get the maximum value from a list

iex> Statistics.max([])
nil
iex> Statistics.max([1,2,3])
3

If a non-empty list is provided, it is a call to Enum.max/1

Link to this function mean(list)
mean(list()) :: number()

Calculate the mean from a list of numbers

Examples

iex> Statistics.mean([])
nil
iex> Statistics.mean([1,2,3])
2.0
Link to this function median(list)
median(list()) :: number()

Get the median value from a list.

Examples

iex> Statistics.median([])
nil
iex> Statistics.median([1,2,3])
2
iex> Statistics.median([1,2,3,4])
2.5
Link to this function min(list)
min(list()) :: number()

Get the minimum value from a list

iex> Statistics.min([])
nil
iex> Statistics.min([1,2,3])
1

If a non-empty list is provided, it is a call to Enum.min/1

Link to this function mode(list)
mode(list()) :: number()

Get the most frequently occuring value

Examples

iex> Statistics.mode([])
nil
iex> Statistics.mode([1,2,3,2,4,5,2,6,7,2,8,9])
2
Link to this function moment(list, n \\ 1)
moment(list(), pos_integer()) :: number()

Calculates the nth moment about the mean for a sample.

Generally used to calculate coefficients of skewness and kurtosis. Returns the n-th central moment as a float The denominator for the moment calculation is the number of observations, no degrees of freedom correction is done.

Examples

iex> Statistics.moment([1,2,3,4,5,6,7,8,9,8,7,6,5,4,3],3)
-1.3440000000000025
iex> Statistics.moment([], 2)
nil
Link to this function percentile(list, n)
percentile(list(), number()) :: number()

Get the nth percentile cutoff from a list

Examples

iex> Statistics.percentile([], 50)
nil
iex> Statistics.percentile([1,2,3,4,5,6,7,8,9],80)
7.4
iex> Statistics.percentile([1,2,3,4,5,6,7,8,9],100)
9
Link to this function quartile(list, atom)
quartile(list(), atom()) :: number()

Get the quartile cutoff value from a list

responds to only first and third quartile.

Examples

iex>  Statistics.quartile([1,2,3,4,5,6,7,8,9],:first)
3
iex>  Statistics.quartile([1,2,3,4,5,6,7,8,9],:third)
7
Link to this function range(list)
range(list()) :: number()

Get range of data

Examples

iex> Statistics.range([1,2,3,4,5,6])
5
Link to this function skew(list)
skew(list()) :: number()

Computes the skewness of a data set.

For normally distributed data, the skewness should be about 0. A skewness value > 0 means that there is more weight in the left tail of the distribution.

Examples

iex> Statistics.skew([])
nil
iex> Statistics.skew([1,2,3,2,1])
0.3436215967445454
Link to this function stdev(list)
stdev(list()) :: number()

Calculate the standard deviation of a list

Examples

iex> Statistics.stdev([])
nil
iex> Statistics.stdev([1,2])
0.5
Link to this function sum(list)
sum(list()) :: number()

Sum the contents of a list

Calls Enum.sum/1

Link to this function trimmed_mean(list, arg2)
trimmed_mean(list(), tuple()) :: number()
trimmed_mean(list(), atom()) :: number()

Calculate the trimmed mean of a list.

Can specify cutoff values as a tuple, or simply choose the IQR min/max as the cutoffs

Examples

iex> Statistics.trimmed_mean([], :iqr)
nil
iex> Statistics.trimmed_mean([1,2,3], {1,3})
2.0
iex> Statistics.trimmed_mean([1,2,3,4,5,5,6,6,7,7,8,8,10,11,12,13,14,15], :iqr)
7.3
Link to this function variance(list)
variance(list()) :: number()

Calculate variance from a list of numbers

Examples

iex> Statistics.variance([])
nil
iex> Statistics.variance([1,2,3,4])
1.25
iex> Statistics.variance([55,56,60,65,54,51,39])
56.48979591836735
Link to this function zscore(list)
zscore(list()) :: list()

Calculate a standard z score for each item in a list

Examples

iex> Statistics.zscore([3,2,3,4,5,6,5,4,3])
[-0.7427813527082074, -1.5784103745049407, -0.7427813527082074,
0.09284766908852597, 0.9284766908852594, 1.7641057126819928,
0.9284766908852594, 0.09284766908852597, -0.7427813527082074]