Next: Basic Statistical Functions, Up: Statistics
Octave can compute various statistics such as the moments of a data set.
If x is a vector, compute the mean of the elements of x
mean (x) = SUM_i x(i) / NIf x is a matrix, compute the mean for each column and return them in a row vector.
With the optional argument opt, the kind of mean computed can be selected. The following options are recognized:
"a"
- Compute the (ordinary) arithmetic mean. This is the default.
"g"
- Computer the geometric mean.
"h"
- Compute the harmonic mean.
If the optional argument dim is supplied, work along dimension dim.
Both dim and opt are optional. If both are supplied, either may appear first.
If x is a vector, compute the median value of the elements of 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 evenIf 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: std, mean.
For vector arguments, return the mean square of the values. For matrix arguments, return a row vector contaning the mean square of each column. With the optional dim argument, returns the mean squared of the values along this dimension.
If x is a vector, compute the standard deviation of the elements of x.
std (x) = sqrt (sumsq (x - mean (x)) / (n - 1))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:
- normalizes with N-1, provides the square root of best unbiased estimator of the variance [default]
- 1:
- normalizes with N, this provides the square root of the second moment around the mean
The third argument dim determines the dimension along which the standard deviation is calculated.
See also: mean, median.
For vector arguments, return the (real) variance of the values. For matrix arguments, return a row vector contaning the variance for each column.
The argument opt determines the type of normalization to use. Valid values are
- 0:
- Normalizes with N-1, provides the best unbiased estimator of the variance [default].
- 1:
- Normalizes with N, this provides the second moment around the mean.
The third argument dim determines the dimension along which the variance is calculated.
Count the most frequently appearing value.
mode
counts the frequency along the first non-singleton dimension and if two or more values have te same frequency returns the smallest of the two in m. The dimension along which to count can be specified by the dim parameter.The variable f counts the frequency of each of the most frequently occuring ellements. The cell array c contains all of the elements with the maximum frequency .
Compute covariance.
If each row of x and y is an observation and each column is a variable, the (i, j)-th entry of
cov (
x,
y)
is the covariance between the i-th variable in x and the j-th variable in y. If called with one argument, computecov (
x,
x)
.
Compute correlation.
The (i, j)-th entry of
cor (
x,
y)
is the correlation between the i-th variable in x and the j-th variable in y.corrcoef(x,y) = cov(x,y)/(std(x)*std(y))For matrices, each row is an observation and each column a variable; vectors are always observations and may be row or column vectors.
cor (
x)
is equivalent tocor (
x,
x)
.Note that the
corrcoef
function does the same ascor
.
Compute correlation.
If each row of x and y is an observation and each column is a variable, the (i, j)-th entry of
corrcoef (
x,
y)
is the correlation between the i-th variable in x and the j-th variable in y.corrcoef(x,y) = cov(x,y)/(std(x)*std(y))If called with one argument, compute
corrcoef (
x,
x)
.
If x is a vector of length N, return the kurtosis
kurtosis (x) = N^(-1) std(x)^(-4) sum ((x - mean(x)).^4) - 3of x. If x is a matrix, return the kurtosis over the first non-singleton dimension. The optional argument dim can be given to force the kurtosis to be given over that dimension.
If x is a vector of length n, return the skewness
skewness (x) = N^(-1) std(x)^(-3) sum ((x - mean(x)).^3)of x. 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.
If x is a matrix, return a matrix with the minimum, first quartile, median, third quartile, maximum, mean, standard deviation, skewness and kurtosis of the columns of x as its rows.
If x is a vector, treat it as a column vector.
If x is a vector, compute the p-th moment of x.
If x is a matrix, return the row vector containing the p-th moment of each column.
With the optional string opt, the kind of moment to be computed can be specified. If opt contains
"c"
or"a"
, central and/or absolute moments are returned. For example,moment (x, 3, "ac")computes the third central absolute moment of x.
If the optional argument dim is supplied, work along dimension dim.