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

NAG Library Routine Document

G01ATF

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

G01ATF 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.

2  Specification

SUBROUTINE G01ATF ( NB, X, IWT, WT, PN, XMEAN, XSD, XSKEW, XKURT, XMIN, XMAX, RCOMM, IFAIL)
INTEGER  NB, IWT, PN, IFAIL
REAL (KIND=nag_wp)  X(NB), WT(*), XMEAN, XSD, XSKEW, XKURT, XMIN, XMAX, RCOMM(20)

3  Description

Given a sample of n observations, denoted by x = xi : i=1,2,,n  and a set of non-negative weights, w = wi : i=1,2,,n , G01ATF calculates a number of quantities:
(a) Mean
x- = i=1 n wi xi W ,   where   W = i=1 n wi .  
(b) Standard deviation
s2 = i=1 n wi xi - x- 2 d ,   where   d = W - i=1 n wi2 W .  
(c) Coefficient of skewness
s3 = i=1 n wi xi - x- 3 d s23 .  
(d) Coefficient of kurtosis
s4 = i=1 n wi xi - x- 4 d s24 -3 .  
(e) Maximum and minimum elements, with wi0.
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, x and w can be split into arbitrary sized blocks and G01ATF called multiple times.

4  References

West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555

5  Parameters

1:     NB – INTEGERInput
On entry: b, 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 G01ATF.
Constraint: NB0.
2:     XNB – REAL (KIND=nag_wp) arrayInput
On entry: the current block of observations, corresponding to xi, for i=k+1,,k+b, where k is the number of observations processed so far and b is the size of the current block of data.
3:     IWT – INTEGERInput
On entry: indicates whether user-supplied weights are provided:
IWT=1
User-supplied weights are given in the array WT.
IWT=0
wi=1, for all i, so no user-supplied weights are given and WT is not referenced.
Constraint: IWT=0 or 1.
4:     WT* – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array WT must be at least NB if IWT=1.
On entry: if IWT=1, WT must contain the user-supplied weights corresponding to the block of data supplied in X, that is wi, for i=k+1,,k+b.
Constraint: if IWT=1, WTi0, for i=1,2,,NB.
5:     PN – INTEGERInput/Output
On entry: the number of valid observations processed so far, that is the number of observations with wi>0, for i=1,2,,k. On the first call to G01ATF, or when starting to summarise a new dataset, PN must be set to 0.
If PN0, it must be the same value as returned by the last call to G01ATF.
On exit: the updated number of valid observations processed, that is the number of observations with wi>0, for i=1,2,,k+b.
Constraint: PN0.
6:     XMEAN – REAL (KIND=nag_wp)Output
On exit: x-, the mean of the first k+b observations.
7:     XSD – REAL (KIND=nag_wp)Output
On exit: s2, the standard deviation of the first k+b observations.
8:     XSKEW – REAL (KIND=nag_wp)Output
On exit: s3, the coefficient of skewness for the first k+b observations.
9:     XKURT – REAL (KIND=nag_wp)Output
On exit: s4, the coefficient of kurtosis for the first k+b observations.
10:   XMIN – REAL (KIND=nag_wp)Output
On exit: the smallest value in the first k+b observations.
11:   XMAX – REAL (KIND=nag_wp)Output
On exit: the largest value in the first k+b observations.
12:   RCOMM20 – REAL (KIND=nag_wp) arrayCommunication Array
On entry: communication array, used to store information between calls to G01ATF. If PN=0, RCOMM need not be initialized, otherwise it must be unchanged since the last call to this routine.
On exit: the updated communication array. The first five elements of RCOMM hold information that may be of interest with
RCOMM1 = i=1 k+b wi RCOMM2 = i=1 k+b wi 2 - i=1 k+b wi2 RCOMM3 = i=1 k+b wi xi - x- 2 RCOMM4 = i=1 k+b wi xi - x- 3 RCOMM5 = i=1 k+b wi xi - x- 4  
the remaining elements of RCOMM are used for workspace and so are undefined.
13:   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.
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.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

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=11
On entry, NB=value.
Constraint: NB0.
IFAIL=31
On entry, IWT=value.
Constraint: IWT=0 or 1.
IFAIL=41
On entry, WTvalue=value.
Constraint: if IWT=1 then WTi0, for i=1,2,,NB.
IFAIL=51
On entry, PN=value.
Constraint: PN0.
IFAIL=52
On entry, PN=value.
On exit from previous call, PN=value.
Constraint: if PN>0, PN must be unchanged since previous call.
IFAIL=53
On entry, the number of valid observations is zero.
IFAIL=71
On exit we were unable to calculate XSKEW or XKURT. A value of 0 has been returned.
IFAIL=72
On exit we were unable to calculate XSD, XSKEW or XKURT. A value of 0 has been returned.
IFAIL=121
RCOMM has been corrupted between calls.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

Not applicable.

8  Parallelism and Performance

G01ATF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

Both G01ATF and G01AUF 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.

10  Example

This example summarises some simulated data. The data is supplied in three blocks, the first consisting of 21 observations, the second 51 observations and the last 28 observations.

10.1  Program Text

Program Text (g01atfe.f90)

10.2  Program Data

Program Data (g01atfe.d)

10.3  Program Results

Program Results (g01atfe.r)


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

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