octave: Descriptive Statistics
26.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.
-- : mean (X)
-- : mean (X, DIM)
-- : mean (X, OPT)
-- : mean (X, DIM, OPT)
Compute the mean of the elements of the vector X.
The mean is defined as
mean (X) = SUM_i X(i) / N
where N is the length of the X vector.
If X is a matrix, compute the mean for each column and return them
in a row vector.
If the optional argument DIM is given, operate along this
dimension.
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.
Both DIM and OPT are optional. If both are supplied, either may
appear first.
See also: median XREFmedian, mode XREFmode.
-- : median (X)
-- : median (X, DIM)
Compute the median value of the elements of the vector X.
When the elements of X are sorted, say ‘S = sort (X)’, the median
is defined as
| S(ceil(N/2)) N odd
median (X) = |
| (S(N/2) + S(N/2+1))/2 N even
If X is of a discrete type such as integer or logical, then the
case of even N rounds up (or toward ‘true’).
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 XREFmean, mode XREFmode.
-- : mode (X)
-- : mode (X, DIM)
-- : [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
the dataset.
The cell array C contains all of the elements with the maximum
frequency.
See also: mean XREFmean, median XREFmedian.
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.
-- : range (X)
-- : 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 XREFiqr, std XREFstd.
-- : iqr (X)
-- : 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 XREFrange, std XREFstd.
-- : meansq (X)
-- : meansq (X, DIM)
Compute the mean square of the elements of the vector X.
The mean square is defined as
meansq (X) = 1/N SUM_i X(i)^2
where N is the length of the X vector.
If X is a matrix, return a row vector containing the mean square of
each column.
If the optional argument DIM is given, operate along this
dimension.
DONTPRINTYET See also: var XREFvar, std XREFstd, *notemoment:
DONTPRINTYET See also: var XREFvar, std XREFstd, moment
XREFmoment.
-- : std (X)
-- : std (X, OPT)
-- : std (X, OPT, DIM)
Compute the standard deviation of the elements of the vector X.
The standard deviation is defined as
std (X) = sqrt ( 1/(N-1) SUM_i (X(i) - mean(X))^2 )
where N is the number of elements of the X vector.
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.
DONTPRINTYET See also: var XREFvar, range XREFrange, *noteiqr:
DONTPRINTYET See also: var XREFvar, range XREFrange, iqr
XREFiqr, mean XREFmean, median XREFmedian.
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.
-- : var (X)
-- : var (X, OPT)
-- : var (X, OPT, DIM)
Compute the variance of the elements of the vector X.
The variance is defined as
var (X) = 1/(N-1) SUM_i (X(i) - mean(X))^2
where N is the length of the X vector.
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 N is equal to 1 the value of OPT is ignored and normalization by
N is used.
If the optional argument DIM is given, operate along this
dimension.
DONTPRINTYET See also: cov XREFcov, std XREFstd, *noteskewness:
DONTPRINTYET DONTPRINTYET See also: cov XREFcov, std XREFstd, skewness
XREFskewness, kurtosis XREFkurtosis, *notemoment:
DONTPRINTYET DONTPRINTYET See also: cov XREFcov, std XREFstd, skewness
XREFskewness, kurtosis XREFkurtosis, moment
XREFmoment.
-- : skewness (X)
-- : skewness (X, FLAG)
-- : skewness (X, FLAG, DIM)
Compute the sample skewness of the elements of X.
The sample skewness is defined as
mean ((X - mean (X)).^3)
skewness (X) = ------------------------.
std (X).^3
The optional argument FLAG controls which normalization is used.
If FLAG is equal to 1 (default value, used when FLAG is omitted or
empty), return the sample skewness as defined above. If FLAG is
equal to 0, return the adjusted skewness coefficient instead:
sqrt (N*(N-1)) mean ((X - mean (X)).^3)
skewness (X, 0) = -------------- * ------------------------.
(N - 2) std (X).^3
where N is the length of the X vector.
The adjusted skewness coefficient is obtained by replacing the
sample second and third central moments by their bias-corrected
versions.
If X is a matrix, or more generally a multi-dimensional array,
return the skewness along the first non-singleton dimension. If
the optional DIM argument is given, operate along this dimension.
DONTPRINTYET See also: var XREFvar, kurtosis XREFkurtosis, *noteDONTPRINTYET See also: var XREFvar, kurtosis XREFkurtosis,
moment XREFmoment.
-- : kurtosis (X)
-- : kurtosis (X, FLAG)
-- : kurtosis (X, FLAG, DIM)
Compute the sample kurtosis of the elements of X.
The sample kurtosis is defined as
mean ((X - mean (X)).^4)
k1 = ------------------------
std (X).^4
The optional argument FLAG controls which normalization is used.
If FLAG is equal to 1 (default value, used when FLAG is omitted or
empty), return the sample kurtosis as defined above. If FLAG is
equal to 0, return the "bias-corrected" kurtosis coefficient
instead:
N - 1
k0 = 3 + -------------- * ((N + 1) * k1 - 3 * (N - 1))
(N - 2)(N - 3)
where N is the length of the X vector.
The bias-corrected kurtosis coefficient is obtained by replacing
the sample second and fourth central moments by their unbiased
versions. It is an unbiased estimate of the population kurtosis
for normal populations.
If X is a matrix, or more generally a multi-dimensional array,
return the kurtosis along the first non-singleton dimension. If
the optional DIM argument is given, operate along this dimension.
DONTPRINTYET See also: var XREFvar, skewness XREFskewness, *noteDONTPRINTYET See also: var XREFvar, skewness XREFskewness,
moment XREFmoment.
-- : moment (X, P)
-- : moment (X, P, TYPE)
-- : moment (X, P, DIM)
-- : moment (X, P, TYPE, DIM)
-- : moment (X, P, DIM, TYPE)
Compute the P-th central moment of the vector X:
1/N SUM_i (X(i) - mean(X))^P
where N is the length of the X vector.
If X is a matrix, return the row vector containing the P-th central
moment of each column.
If the optional argument DIM is given, operate along this
dimension.
The optional string TYPE specifies the type of moment to be
computed. Valid options are:
"c"
Central Moment (default).
"a"
"ac"
Absolute Central Moment. The moment about the mean ignoring
sign defined as
1/N SUM_i (abs (X(i) - mean(X)))^P
"r"
Raw Moment. The moment about zero defined as
moment (X) = 1/N SUM_i X(i)^P
"ar"
Absolute Raw Moment. The moment about zero ignoring sign
defined as
1/N SUM_i ( abs (X(i)) )^P
If both TYPE and DIM are given they may appear in any order.
DONTPRINTYET See also: var XREFvar, skewness XREFskewness, *noteDONTPRINTYET See also: var XREFvar, skewness XREFskewness,
kurtosis XREFkurtosis.
-- : Q = quantile (X)
-- : Q = quantile (X, P)
-- : Q = quantile (X, P, DIM)
-- : Q = quantile (X, P, DIM, METHOD)
For a sample, X, calculate the quantiles, Q, corresponding to the
cumulative probability values in P. All non-numeric values (NaNs)
of X are ignored.
If X is a matrix, compute the quantiles for each column and return
them in a matrix, such that the i-th row of Q contains the P(i)th
quantiles of each column of X.
If P is unspecified, return the quantiles for ‘[0.00 0.25 0.50 0.75
1.00]’. The optional argument DIM determines the dimension along
which the quantiles are calculated. If DIM is omitted it defaults
to the first non-singleton dimension.
The methods available to calculate sample quantiles are the nine
methods used by R (<http://www.r-project.org/>). The default value
is METHOD = 5.
Discontinuous sample quantile methods 1, 2, and 3
1. Method 1: Inverse of empirical distribution function.
2. Method 2: Similar to method 1 but with averaging at
discontinuities.
3. Method 3: SAS definition: nearest even order statistic.
Continuous sample quantile methods 4 through 9, where P(k) is the
linear interpolation function respecting each method’s
representative cdf.
4. Method 4: P(k) = k / N. That is, linear interpolation of the
empirical cdf, where N is the length of P.
5. Method 5: P(k) = (k - 0.5) / N. That is, a piecewise linear
function where the knots are the values midway through the
steps of the empirical cdf.
6. Method 6: P(k) = k / (N + 1).
7. Method 7: P(k) = (k - 1) / (N - 1).
8. Method 8: P(k) = (k - 1/3) / (N + 1/3). The resulting
quantile estimates are approximately median-unbiased
regardless of the distribution of X.
9. Method 9: P(k) = (k - 3/8) / (N + 1/4). The resulting
quantile estimates are approximately unbiased for the expected
order statistics if X is normally distributed.
Hyndman and Fan (1996) recommend method 8. Maxima, S, and R
(versions prior to 2.0.0) use 7 as their default. Minitab and SPSS
use method 6. MATLAB uses method 5.
References:
• Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New
S Language. Wadsworth & Brooks/Cole.
• Hyndman, R. J. and Fan, Y. (1996) Sample quantiles in
statistical packages, American Statistician, 50, 361–365.
• R: A Language and Environment for Statistical Computing;
<http://cran.r-project.org/doc/manuals/fullrefman.pdf>.
Examples:
x = randi (1000, [10, 1]); # Create empirical data in range 1-1000
q = quantile (x, [0, 1]); # Return minimum, maximum of distribution
q = quantile (x, [0.25 0.5 0.75]); # Return quartiles of distribution
See also: prctile XREFprctile.
-- : Q = prctile (X)
-- : Q = prctile (X, P)
-- : Q = prctile (X, P, DIM)
For a sample X, compute the quantiles, Q, corresponding to the
cumulative probability values, P, in percent.
If X is a matrix, compute the percentiles for each column and
return them in a matrix, such that the i-th row of Q contains the
P(i)th percentiles of each column of X.
If P is unspecified, return the quantiles for ‘[0 25 50 75 100]’.
The optional argument DIM determines the dimension along which the
percentiles are calculated. If DIM is omitted it defaults to the
first non-singleton dimension.
Programming Note: All non-numeric values (NaNs) of X are ignored.
See also: quantile XREFquantile.
A summary view of a data set can be generated quickly with the
‘statistics’ function.
-- : statistics (X)
-- : 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.
DONTPRINTYET See also: min XREFmin, max XREFmax, *notemedian:
DONTPRINTYET DONTPRINTYET See also: min XREFmin, max XREFmax, median
XREFmedian, mean XREFmean, std XREFstd, *noteDONTPRINTYET DONTPRINTYET See also: min XREFmin, max XREFmax, median
XREFmedian, mean XREFmean, std XREFstd,
skewness XREFskewness, kurtosis XREFkurtosis.