G01AAF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G01AAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G01AAF calculates the mean, standard deviation, coefficients of skewness and kurtosis, and the maximum and minimum values for a set of ungrouped data. Weighting may be used.

2  Specification

SUBROUTINE G01AAF ( N, X, IWT, WT, XMEAN, S2, S3, S4, XMIN, XMAX, WTSUM, IFAIL)
INTEGER  N, IWT, IFAIL
REAL (KIND=nag_wp)  X(N), WT(N), XMEAN, S2, S3, S4, XMIN, XMAX, WTSUM

3  Description

The data consist of a single sample of n observations, denoted by xi, with corresponding weights, wi, for i=1,2,,n.
If no specific weighting is required, then each wi is set to 1.
The quantities computed are:
(a) The sum of the weights
W=i=1nwi.
(b) Mean
x-=i= 1nwixiW.
(c) Standard deviation
s2=i=1nwi xi-x- 2d,   where  d=W-i=1nwi2W.
(d) Coefficient of skewness
s3=i= 1nwi xi-x- 3 d×s23 .
(e) Coefficient of kurtosis
s4=i=1nwi xi-x- 4 d×s24 -3.
(f) Maximum and minimum elements of the sample.
(g) The number of observations for which wi>0, i.e., the number of valid observations. Suppose m observations are valid, then the quantities in (c), (d) and (e) will be computed if m2, and will be based on m-1 degrees of freedom. The other quantities are evaluated provided m1.

4  References

None.

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N1.
2:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the sample observations, xi, for i=1,2,,n.
3:     IWT – INTEGERInput/Output
On exit: IWT is used to indicate the number of valid observations, m; see (g) in Section 3 above.
4:     WT(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if IWT=1, then the elements of WT must contain the weights associated with the observations, wi, for i=1,2,,n.
If IWT=0, then the elements of WT need not be set.
On exit: if IWT=1 the elements of WT are unchanged.
If IWT=0 each element of WT will be assigned the value 1.0.
5:     XMEAN – REAL (KIND=nag_wp)Output
6:     S2 – REAL (KIND=nag_wp)Output
On exit: the standard deviation, s2.
7:     S3 – REAL (KIND=nag_wp)Output
On exit: the coefficient of skewness, s3.
8:     S4 – REAL (KIND=nag_wp)Output
On exit: the coefficient of kurtosis, s4.
9:     XMIN – REAL (KIND=nag_wp)Output
10:   XMAX – REAL (KIND=nag_wp)Output
11:   WTSUM – REAL (KIND=nag_wp)Output
On exit: the sum of the weights in the array WT, that is i=1nwi. This will be N if IWT was 0 on entry.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,N<1.
IFAIL=2
The number of valid cases, m, is 1. In this case, standard deviation and coefficients of skewness and of kurtosis cannot be calculated.
IFAIL=3
Either the number of valid cases is 0, or at least one weight is negative.

7  Accuracy

The method used is believed to be stable.

8  Further Comments

The time taken by G01AAF is approximately proportional to n.

9  Example

This example summarises a number of datasets. For each dataset the observations and, optionally, weights are read and printed. G01AAF is then called and the calculated quantities are printed.

9.1  Program Text

Program Text (g01aafe.f90)

9.2  Program Data

Program Data (g01aafe.d)

9.3  Program Results

Program Results (g01aafe.r)


G01AAF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2011