## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g01adf ( k, x, s2, s3, s4, n,
 Integer, Intent (In) :: k, ifreq(k) Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: n Real (Kind=nag_wp), Intent (In) :: x(k) Real (Kind=nag_wp), Intent (Out) :: xmean, s2, s3, s4
#include <nag.h>
 void g01adf_ (const Integer *k, const double x[], const Integer ifreq[], double *xmean, double *s2, double *s3, double *s4, Integer *n, Integer *ifail)
The routine may be called by the names g01adf or nagf_stat_summary_freq.

## 3Description

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:
1. (a)total frequency,
 $n=∑i= 1 k- 1fi.$
2. (b)mean,
 $y¯=∑i=1 k-1fiyin.$
3. (c)standard deviation,
 $s2=∑i= 1 k- 1fi (yi-y¯) 2 (n-1) , n≥ 2.$
4. (d)coefficient of skewness,
 $s3=∑i=1 k-1fi (yi-y¯) 3 (n-1)×s23 , n≥2.$
5. (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:
1. (i)for $k>2$,
 $x1 = (3y1-y2)/2 xj = (yj-1+yj)/2, j=2,…,k-1 xk = (3yk-1-yk-2)/2$
2. (ii)for $k=2$,
 $x1=y1-a and x2=y1+a for any ​a>0 .$
None.

## 5Arguments

1: $\mathbf{k}$Integer Input
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: $\mathbf{x}\left({\mathbf{k}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{ifreq}\left({\mathbf{k}}\right)$Integer array Input
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: $\mathbf{xmean}$Real (Kind=nag_wp) Output
On exit: the mean value, $\overline{y}$.
5: $\mathbf{s2}$Real (Kind=nag_wp) Output
On exit: the standard deviation, ${s}_{2}$.
6: $\mathbf{s3}$Real (Kind=nag_wp) Output
On exit: the coefficient of skewness, ${s}_{3}$.
7: $\mathbf{s4}$Real (Kind=nag_wp) Output
On exit: the coefficient of kurtosis, ${s}_{4}$.
8: $\mathbf{n}$Integer Output
On exit: the total frequency, $n$.
9: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{k}}>1$.
${\mathbf{ifail}}=2$
On entry, $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{x}}\left(\mathit{I}-1\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{x}}\left(\mathit{I}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{x}}\left(\mathit{I}-1\right)\le {\mathbf{x}}\left(\mathit{I}\right)$.
${\mathbf{ifail}}=3$
Either ${\mathbf{ifreq}}\left(i\right)<0$ for some $i$, or the sum of frequencies is zero.
${\mathbf{ifail}}=4$
The total frequency, $n$, is less than $2$, hence the quantities ${s}_{2}$, ${s}_{3}$ and ${s}_{4}$ cannot be calculated.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The method used is believed to be stable.

## 8Parallelism and Performance

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

## 10Example

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.