Next: Basic Statistical Functions, Up: Statistics

### 25.1 Descriptive Statistics

One principal goal of descriptive statistics is to represent the essence of a large data set concisely. Octave provides the mean, median, and mode functions which all summarize a data set with just a single number corresponding to the central tendency of the data.

— Function File: mean (x)
— Function File: mean (x, dim)
— Function File: mean (x, opt)
— Function File: mean (x, dim, opt)

> Compute the mean of the elements of the vector x.

>               mean (x) = SUM_i x(i) / N

> If x is a matrix, compute the mean for each column and return them in a row vector.

> The optional argument opt selects the type of mean to compute. The following options are recognized:

> "a"
>   Compute the (ordinary) arithmetic mean. [default]
> "g"
>   Compute the geometric mean.
> "h"
>   Compute the harmonic mean.

> If the optional argument dim is given, operate along this dimension.

> Both dim and opt are optional. If both are supplied, either may appear first.

> See also: median, mode.

— Function File: median (x)
— Function File: median (x, dim)

> Compute the median value of the elements of the vector x. If the elements of x are sorted, the median is defined as

>                           x(ceil(N/2)),             N odd
>               median(x) =
>                           (x(N/2) + x((N/2)+1))/2,  N even

> If x is a matrix, compute the median value for each column and return them in a row vector. If the optional dim argument is given, operate along this dimension.

> See also: mean, mode.

— Function File: mode (x)
— Function File: mode (x, dim)
— Function File: [m, f, c] = mode (...)

> Compute the most frequently occurring value in a dataset (mode). `mode` determines the frequency of values along the first non-singleton dimension and returns the value with the highest frequency. If two, or more, values have the same frequency `mode` returns the smallest.

> If the optional argument dim is given, operate along this dimension.

> The return variable f is the number of occurrences of the mode in in the dataset. The cell array c contains all of the elements with the maximum frequency.

> See also: mean, median.

Using just one number, such as the mean, to represent an entire data set may not give an accurate picture of the data. One way to characterize the fit is to measure the dispersion of the data. Octave provides several functions for measuring dispersion.

— Function File: range (x)
— Function File: range (x, dim)

> Return the range, i.e., the difference between the maximum and the minimum of the input data. If x is a vector, the range is calculated over the elements of x. If x is a matrix, the range is calculated over each column of x.

> If the optional argument dim is given, operate along this dimension.

> The range is a quickly computed measure of the dispersion of a data set, but is less accurate than `iqr` if there are outlying data points.

> See also: iqr, std.

— Function File: iqr (x)
— Function File: iqr (x, dim)

> Return the interquartile range, i.e., the difference between the upper and lower quartile of the input data. If x is a matrix, do the above for first non-singleton dimension of x.

> If the optional argument dim is given, operate along this dimension.

> As a measure of dispersion, the interquartile range is less affected by outliers than either `range` or `std`.

> See also: range, std.

— Function File: meansq (x)
— Function File: meansq (x, dim)

> Compute the mean square of the elements of the vector x.

>               std (x) = 1/N SUM_i x(i)^2

> For matrix arguments, return a row vector containing the mean square of each column.

> If the optional argument dim is given, operate along this dimension.

> See also: var, std, moment.

— Function File: std (x)
— Function File: std (x, opt)
— Function File: std (x, opt, dim)

> Compute the standard deviation of the elements of the vector x.

>               std (x) = sqrt ( 1/(N-1) SUM_i (x(i) - mean(x))^2 )

> where N is the number of elements.

> If x is a matrix, compute the standard deviation for each column and return them in a row vector.

> The argument opt determines the type of normalization to use. Valid values are

> 0:
>   normalize with N-1, provides the square root of the best unbiased estimator of the variance [default]
> 1:
>   normalize with N, this provides the square root of the second moment around the mean

> If the optional argument dim is given, operate along this dimension.

> See also: var, range, iqr, mean, median.

In addition to knowing the size of a dispersion it is useful to know the shape of the data set. For example, are data points massed to the left or right of the mean? Octave provides several common measures to describe the shape of the data set. Octave can also calculate moments allowing arbitrary shape measures to be developed.

— Function File: var (x)
— Function File: var (x, opt)
— Function File: var (x, opt, dim)

> Compute the variance of the elements of the vector x.

>               std (x) = 1/(N-1) SUM_i (x(i) - mean(x))^2

> If x is a matrix, compute the variance for each column and return them in a row vector.

> The argument opt determines the type of normalization to use. Valid values are

> 0:
>   normalize with N-1, provides the best unbiased estimator of the variance [default]
> 1:
>   normalizes with N, this provides the second moment around the mean

> If the optional argument dim is given, operate along this dimension.

> See also: cov, std, skewness, kurtosis, moment.

— Function File: skewness (x)
— Function File: skewness (x, dim)

> Compute the skewness of the elements of the vector x.

>               skewness (x) = N^(-1) std(x)^(-3) sum ((x - mean(x)).^3)

> If x is a matrix, return the skewness along the first non-singleton dimension of the matrix. If the optional dim argument is given, operate along this dimension.

> See also: var, kurtosis, moment.

— Function File: kurtosis (x)
— Function File: kurtosis (x, dim)

> Compute the kurtosis of the elements of the vector x.

>               kurtosis (x) = N^(-1) std(x)^(-4) sum ((x - mean(x)).^4) - 3

> If x is a matrix, return the kurtosis over the first non-singleton dimension of the matrix. If the optional dim argument is given, operate along this dimension.

> Note: The definition of kurtosis above yields a kurtosis of zero for the stdnormal distribution and is sometimes referred to as "excess kurtosis". To calculate kurtosis without the normalization factor of -3 use `moment (`x`, 4, 'c') / std (`x`)^4`.

> See also: var, skewness, moment.

— Function File: moment (x, p)
— Function File: moment (x, p, type)
— Function File: moment (x, p, dim)
— Function File: moment (x, p, type, dim)
— Function File: moment (x, p, dim, type)

> Compute the p-th moment of the vector x about zero.

>               moment (x) = 1/N SUM_i x(i)^p

> If x is a matrix, return the row vector containing the p-th moment of each column.

> The optional string type specifies the type of moment to be computed. Valid options are:

> "c"
>   Central Moment. The moment about the mean defined as

>                      1/N SUM_i (x(i) - mean(x))^p

> "a"
>   Absolute Moment. The moment about zero ignoring sign defined as

>                      1/N SUM_i ( abs(x(i)) )^p

> "ac"
>   Absolute Central Moment. Defined as

>                      1/N SUM_i ( abs(x(i) - mean(x)) )^p

> If the optional argument dim is given, operate along this dimension.

> If both type and dim are given they may appear in any order.

> See also: var, skewness, kurtosis.

A summary view of a data set can be generated quickly with the `statistics` function.

— Function File: statistics (x)
— Function File: statistics (x, dim)

> Return a vector with the minimum, first quartile, median, third quartile, maximum, mean, standard deviation, skewness, and kurtosis of the elements of the vector x.

> If x is a matrix, calculate statistics over the first non-singleton dimension. If the optional argument dim is given, operate along this dimension.

> See also: min, max, median, mean, std, skewness, kurtosis.