nag_summary_stats_freq (g01adc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_summary_stats_freq (g01adc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_summary_stats_freq (g01adc) calculates the mean, standard deviation and coefficients of skewness and kurtosis for data grouped in a frequency distribution.

2  Specification

#include <nag.h>
#include <nagg01.h>
void  nag_summary_stats_freq (Integer k, const double x[], const Integer ifreq[], double *xmean, double *xsd, double *xskew, double *xkurt, Integer *n, NagError *fail)

3  Description

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 nag_summary_stats_freq (g01adc) 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 function has been developed primarily for groupings of a continuous variable. If, however, the function 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 .

4  References

None.

5  Arguments

1:     kIntegerInput
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:     x[k]const doubleInput
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 x[i-1] and x[i], for i=1,2,,k-1.
Constraint: x[i]<x[i+1], for i=0,1,,k-2.
3:     ifreq[k]const IntegerInput
On entry: the ith element of ifreq must contain the frequency associated with the ith class, for i=1,2,,k-1. ifreq[k-1] is not used by the function.
Constraints:
  • ifreq[i-1]0, for i=1,2,,k-1;
  • i=1 k-1ifreq[i-1]>0.
4:     xmeandouble *Output
On exit: the mean value, y-.
5:     xsddouble *Output
On exit: the standard deviation, s2.
6:     xskewdouble *Output
On exit: the coefficient of skewness, s3.
7:     xkurtdouble *Output
On exit: the coefficient of kurtosis, s4.
8:     nInteger *Output
On exit: the total frequency, n.
9:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_FREQ_CONS
Either ifreq[i]<0 for some i, or the sum of frequencies is zero.
NE_FREQ_SUM
The total frequency is less than 2.
NE_INT
On entry, k=value.
Constraint: k>1.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_NOT_INCREASING
On entry, i=value, x[i-2]=value and x[i-1]=value.
Constraint: x[i-2]x[i-1].

7  Accuracy

The method used is believed to be stable.

8  Further Comments

The time taken by nag_summary_stats_freq (g01adc) 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 nag_summary_stats_freq (g01adc) has been successfully called, the input data and calculated quantities are printed. In the example, there is one set of data, with 14 classes.

9.1  Program Text

Program Text (g01adce.c)

9.2  Program Data

Program Data (g01adce.d)

9.3  Program Results

Program Results (g01adce.r)


nag_summary_stats_freq (g01adc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG C Library Manual

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