G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01AAF

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.

## 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 ${x}_{i}$, with corresponding weights, ${w}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
If no specific weighting is required, then each ${w}_{i}$ 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 ${w}_{i}>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 $m\ge 2$, and will be based on $m-1$ degrees of freedom. The other quantities are evaluated provided $m\ge 1$.

None.

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}\ge 1$.
2:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the sample observations, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     IWT – INTEGERInput/Output
On entry: indicates whether weights are to be supplied by you or not. In the latter case, the weights will be assumed equal and assigned the value $1.0$ in the routine.
${\mathbf{IWT}}=0$
Indicates no user-supplied weights.
${\mathbf{IWT}}=1$
Indicates user-supplied weights are required, and they will be supplied in the array WT.
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 ${\mathbf{IWT}}=1$, the elements of WT must contain the weights associated with the observations, ${w}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{IWT}}=0$, the elements of WT need not be set.
On exit: if ${\mathbf{IWT}}=1$, the elements of WT are unchanged.
If ${\mathbf{IWT}}=0$, each element of WT will be assigned the value $1.0$.
5:     XMEAN – REAL (KIND=nag_wp)Output
On exit: the mean, $\stackrel{-}{x}$.
6:     S2 – REAL (KIND=nag_wp)Output
On exit: the standard deviation, ${s}_{2}$.
7:     S3 – REAL (KIND=nag_wp)Output
On exit: the coefficient of skewness, ${s}_{3}$.
8:     S4 – REAL (KIND=nag_wp)Output
On exit: the coefficient of kurtosis, ${s}_{4}$.
9:     XMIN – REAL (KIND=nag_wp)Output
On exit: the smallest value in the sample.
10:   XMAX – REAL (KIND=nag_wp)Output
On exit: the largest value in the sample.
11:   WTSUM – REAL (KIND=nag_wp)Output
On exit: the sum of the weights in the array WT, that is $\sum _{i=1}^{n}{w}_{i}$. This will be N if IWT was $0$ on entry.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}<1$.
${\mathbf{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.
${\mathbf{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.

The time taken by G01AAF is approximately proportional to $n$.

## 9  Example

This example summarises an (optionally weighted) dataset and displays the results.

### 9.1  Program Text

Program Text (g01aafe.f90)

### 9.2  Program Data

Program Data (g01aafe.d)

### 9.3  Program Results

Program Results (g01aafe.r)