PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_stat_summary_onevar (g01at)
Purpose
nag_stat_summary_onevar (g01at) calculates the mean, standard deviation, coefficients of skewness and kurtosis, and the maximum and minimum values for a set of (optionally weighted) data. The input data can be split into arbitrary sized blocks, allowing large datasets to be summarised.
Syntax
[
pn,
xmean,
xsd,
xskew,
xkurt,
xmin,
xmax,
rcomm,
ifail] = g01at(
x, 'nb',
nb, 'wt',
wt, 'pn',
pn, 'rcomm',
rcomm)
[
pn,
xmean,
xsd,
xskew,
xkurt,
xmin,
xmax,
rcomm,
ifail] = nag_stat_summary_onevar(
x, 'nb',
nb, 'wt',
wt, 'pn',
pn, 'rcomm',
rcomm)
Description
Given a sample of
observations, denoted by
and a set of non-negative weights,
,
nag_stat_summary_onevar (g01at) calculates a number of quantities:
(a) |
Mean
|
(b) |
Standard deviation
|
(c) |
Coefficient of skewness
|
(d) |
Coefficient of kurtosis
|
(e) |
Maximum and minimum elements, with . |
These quantities are calculated using the one pass algorithm of
West (1979).
For large datasets, or where all the data is not available at the same time, and can be split into arbitrary sized blocks and nag_stat_summary_onevar (g01at) called multiple times.
References
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The current block of observations, corresponding to
, for , where is the number of observations processed so far and is the size of the current block of data.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
x.
, the number of observations in the current block of data. The size of the block of data supplied in
x and
wt can vary; therefore
nb can change between calls to
nag_stat_summary_onevar (g01at).
Constraint:
.
- 2:
– double array
-
The dimension of the array
wt
must be at least
if
If
,
wt must contain the user-supplied weights corresponding to the block of data supplied in
x, that is
, for
.
Constraint:
if , , for .
- 3:
– int64int32nag_int scalar
Default:
The number of valid observations processed so far, that is the number of observations with
, for
. On the first call to
nag_stat_summary_onevar (g01at), or when starting to summarise a new dataset,
pn must be set to
.
If , it must be the same value as returned by the last call to nag_stat_summary_onevar (g01at).
- 4:
– double array
-
Communication array, used to store information between calls to
nag_stat_summary_onevar (g01at). If
,
rcomm need not be initialized, otherwise it must be unchanged since the last call to this function.
Output Parameters
- 1:
– int64int32nag_int scalar
Default:
The updated number of valid observations processed, that is the number of observations with
, for .
- 2:
– double scalar
-
, the mean of the first observations.
- 3:
– double scalar
-
, the standard deviation of the first observations.
- 4:
– double scalar
-
, the coefficient of skewness for the first observations.
- 5:
– double scalar
-
, the coefficient of kurtosis for the first observations.
- 6:
– double scalar
-
The smallest value in the first observations.
- 7:
– double scalar
-
The largest value in the first observations.
- 8:
– double array
-
The updated communication array. The first five elements of
rcomm hold information that may be of interest with
the remaining elements of
rcomm are used for workspace and so are undefined.
- 9:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
Constraint: .
-
-
Constraint: or .
-
-
Constraint: if then , for .
-
-
Constraint: .
-
-
Constraint: if
,
pn must be unchanged since previous call.
- W
-
On entry, the number of valid observations is zero.
- W
-
On exit we were unable to calculate
xskew or
xkurt. A value of
has been returned.
- W
-
On exit we were unable to calculate
xsd,
xskew or
xkurt. A value of
has been returned.
-
-
rcomm has been corrupted between calls.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
Both
nag_stat_summary_onevar (g01at) and
nag_stat_summary_onevar_combine (g01au) consolidate results from multiple summaries. Whereas the former can only be used to combine summaries calculated sequentially, the latter combines summaries calculated in an arbitrary order allowing, for example, summaries calculated on different processing units to be combined.
Example
This example summarises some simulated data. The data is supplied in three blocks, the first consisting of observations, the second observations and the last observations.
Open in the MATLAB editor:
g01at_example
function g01at_example
fprintf('g01at example results\n\n');
x1 = [-0.62; -1.92; -1.72; -6.35; 2.00; 7.65; 6.15;
3.81; 4.87; -0.51; 6.88; -5.85; -0.72; 0.66;
2.23; -1.61; -0.15; -1.15; -8.74; -3.94; 3.61];
wt1 = [4.91; 0.25; 3.90; 3.75; 1.17; 3.19; 2.66;
0.02; 3.59; 3.63; 4.83; 3.72; 1.72; 0.78;
4.74; 1.72; 3.94; 1.33; 0.51; 2.40; 3.90];
x2 = [-0.66; -2.39; -6.25; 1.23; 2.27; -2.27; 10.12;
8.29; -2.99; 8.71; -0.74; 0.02; 1.22; 1.70;
4.30; 2.99; -0.83; -1.00; 6.57; 2.32; -3.47;
-1.41; -5.26; 0.53; 1.80; 4.79; -3.04; 1.20;
-3.21; -3.75; 0.86; 1.27; -5.95; -5.27; 1.63;
3.59; -0.01; -1.38; -4.71; -4.82; 3.55; 0.46;
2.57; 1.76; -4.05; 1.23; -1.99; 3.20; -0.65;
8.42; -6.01];
x3 = [ 1.13; -8.86; 5.92; -1.71; -3.99; 6.57; -2.01;
-2.29; -1.11; 7.14; 4.84; -4.44; -3.32; 10.25;
-2.11; 8.02; -7.31; 2.80; -1.20; 1.01; 1.37;
-2.28; 1.28; -3.95; 3.43; -0.61; 4.85; -0.11];
rcomm = zeros(20,1);
[pn, xmean, xsd, xskew, xkurt, xmin, xmax, rcomm, ifail] = ...
g01at(x1, 'wt', wt1);
[pn, xmean, xsd, xskew, xkurt, xmin, xmax, rcomm, ifail] = ...
g01at(x2, 'pn', pn, 'rcomm', rcomm);
[pn, xmean, xsd, xskew, xkurt, xmin, xmax, rcomm, ifail] = ...
g01at(x3, 'pn', pn, 'rcomm', rcomm);
fprintf('Data supplied in 3 blocks\n');
fprintf('%d valid observations\n', pn);
fprintf('Mean %13.2f\n', xmean);
fprintf('Std devn %13.2f\n', xsd);
fprintf('Skewness %13.2f\n', xskew);
fprintf('Kurtosis %13.2f\n', xkurt);
fprintf('Minimum %13.2f\n', xmin);
fprintf('Maximum %13.2f\n', xmax);
g01at example results
Data supplied in 3 blocks
100 valid observations
Mean 0.51
Std devn 4.24
Skewness 0.18
Kurtosis -0.59
Minimum -8.86
Maximum 10.25
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015