NAG Library Routine Document

g01adf (summary_freq)


    1  Purpose
    7  Accuracy


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


Fortran Interface
Subroutine g01adf ( k, x, ifreq, xmean, s2, s3, s4, n, ifail)
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
C Header Interface
#include nagmk26.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 input data consist of a univariate frequency distribution, denoted by fi, for i=1,2,,k-1, and the boundary values of the classes xi, for i=1,2,,k. Thus the frequency associated with the interval xi,xi+1 is fi, 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 ,  n2.  
(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 y1,,yk-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 .  




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: k>1.
2:     xk – 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 i is bounded by the values in xi and xi+1, for i=1,2,,k-1.
Constraint: xi<xi+1, for i=1,2,,k-1.
3:     ifreqk – Integer arrayInput
On entry: the ith element of ifreq must contain the frequency associated with the ith class, for i=1,2,,k-1. ifreqk is not used by the routine.
  • ifreqi0, for i=1,2,,k-1;
  • i=1 k-1ifreqi>0.
4:     xmean – Real (Kind=nag_wp)Output
On exit: the mean value, y-.
5:     s2 – Real (Kind=nag_wp)Output
On exit: the standard deviation, s2.
6:     s3 – Real (Kind=nag_wp)Output
On exit: the coefficient of skewness, s3.
7:     s4 – Real (Kind=nag_wp)Output
On exit: the coefficient of kurtosis, s4.
8:     n – IntegerOutput
On exit: the total frequency, n.
9:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

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:
On entry, k=value.
Constraint: k>1.
On entry, I=value, xI-1=value and xI=value.
Constraint: xI-1xI.
Either ifreqi<0 for some i, or the sum of frequencies is zero.
The total frequency, n, is less than 2, hence the quantities s2, s3 and s4 cannot be calculated.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


The method used is believed to be stable.

Parallelism and Performance

g01adf is not threaded in any implementation.

Further Comments

The time taken by g01adf increases linearly with k.


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.

Program Text

Program Text (g01adfe.f90)

Program Data

Program Data (g01adfe.d)

Program Results

Program Results (g01adfe.r)

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