G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

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

G01ADF calculates the mean, standard deviation and coefficients of skewness and kurtosis for data grouped in a frequency distribution.

## 2  Specification

 SUBROUTINE G01ADF ( K, X, IFREQ, XMEAN, S2, S3, S4, N, IFAIL)
 INTEGER K, IFREQ(K), N, IFAIL REAL (KIND=nag_wp) X(K), XMEAN, S2, S3, S4

## 3  Description

The input data consist of a univariate frequency distribution, denoted by ${f}_{i}$, for $\mathit{i}=1,2,\dots ,k-1$, and the boundary values of the classes ${x}_{i}$, for $\mathit{i}=1,2,\dots ,k$. Thus the frequency associated with the interval $\left({x}_{i},{x}_{i+1}\right)$ is ${f}_{i}$, and G01ADF assumes that all the values in this interval are concentrated at the point
 $yi=xi+1+xi/2, i=1,2,…,k-1.$
The following quantities are calculated:
(a) total frequency,
 $n=∑i= 1 k- 1fi.$
(b) mean,
 $y-=∑i=1 k-1fiyin.$
(c) standard deviation,
 $s2=∑i= 1 k- 1fi yi-y- 2 n- 1 , n≥ 2.$
(d) coefficient of skewness,
 $s3=∑i=1 k-1fi yi-y- 3 n-1×s23 , n≥2.$
(e) coefficient of kurtosis,
 $s4=∑i= 1 k- 1fi yi-y- 4 n- 1×s24 - 3, n≥ 2.$
The routine has been developed primarily for groupings of a continuous variable. If, however, the routine is to be used on the frequency distribution of a discrete variable, taking the values ${y}_{1},\dots ,{y}_{k-1}$, then the boundary values for the classes may be defined as follows:
(i) for $k>2$,
 $x1=3y1-y2/2 xj=yj-1+yj/2, j=2,…,k-1 xk=3yk-1-yk-2/2$
(ii) for $k=2$,
 $x1=y1-a and x2=y1+a for any ​a>0 .$

None.

## 5  Parameters

1:     K – INTEGERInput
On entry: $k$, the number of class boundaries, which is one more than the number of classes of the frequency distribution.
Constraint: ${\mathbf{K}}>1$.
2:     X(K) – REAL (KIND=nag_wp) arrayInput
On entry: the elements of X must contain the boundary values of the classes in ascending order, so that class $\mathit{i}$ is bounded by the values in ${\mathbf{X}}\left(\mathit{i}\right)$ and ${\mathbf{X}}\left(\mathit{i}+1\right)$, for $\mathit{i}=1,2,\dots ,k-1$.
Constraint: ${\mathbf{X}}\left(\mathit{i}\right)<{\mathbf{X}}\left(\mathit{i}+1\right)$, for $\mathit{i}=1,2,\dots ,k-1$.
3:     IFREQ(K) – INTEGER arrayInput
On entry: the $\mathit{i}$th element of IFREQ must contain the frequency associated with the $\mathit{i}$th class, for $\mathit{i}=1,2,\dots ,k-1$. ${\mathbf{IFREQ}}\left(k\right)$ is not used by the routine.
Constraints:
• ${\mathbf{IFREQ}}\left(\mathit{i}\right)\ge 0$, for $\mathit{i}=1,2,\dots ,k-1$;
• $\sum _{i=1}^{k-1}{\mathbf{IFREQ}}\left(i\right)>0$.
4:     XMEAN – REAL (KIND=nag_wp)Output
On exit: the mean value, $\stackrel{-}{y}$.
5:     S2 – REAL (KIND=nag_wp)Output
On exit: the standard deviation, ${s}_{2}$.
6:     S3 – REAL (KIND=nag_wp)Output
On exit: the coefficient of skewness, ${s}_{3}$.
7:     S4 – REAL (KIND=nag_wp)Output
On exit: the coefficient of kurtosis, ${s}_{4}$.
8:     N – INTEGEROutput
On exit: the total frequency, $n$.
9:     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{K}}\le 1$.
${\mathbf{IFAIL}}=2$
 On entry, the boundary values of the classes in X are not in ascending order.
${\mathbf{IFAIL}}=3$
 On entry, $\sum _{i=1}^{k-1}{\mathbf{IFREQ}}\left(i\right)=0$ or ${\mathbf{IFREQ}}\left(i\right)<0$ for some $i$, for $i=1,2,\dots ,k-1$.
${\mathbf{IFAIL}}=4$
The total frequency, $n$, is less than $2$, hence the quantities ${s}_{2}$, ${s}_{3}$ and ${s}_{4}$ cannot be calculated.

## 7  Accuracy

The method used is believed to be stable.

The time taken by G01ADF increases linearly with $k$.

## 9  Example

In the example program, NPROB determines the number of sets of data to be analysed. For each analysis, the boundary values of the classes and the frequencies are read. After G01ADF has been successfully called, the input data and calculated quantities are printed. In the example, there is one set of data, with $14$ classes.