NAG CL Interface
g01aec (frequency_​table)

Settings help

CL Name Style:


1 Purpose

g01aec constructs a frequency distribution of a variable, according to either user-supplied, or function-calculated class boundary values.

2 Specification

#include <nag.h>
void  g01aec (Integer n, const double x[], Integer num_class, Nag_ClassBoundary classb, double cint[], Integer ifreq[], double *xmin, double *xmax, NagError *fail)
The function may be called by the names: g01aec, nag_stat_frequency_table or nag_frequency_table.

3 Description

The data consists of a sample of n observations of a continuous variable, denoted by xi, for i=1,2,,n. Let a = min(x1,,xn) and b = max(x1,,xn) .
g01aec constructs a frequency distribution with k(>1) classes denoted by fi, for i=1,2,,k.
The boundary values may be either user-supplied, or function-calculated, and are denoted by yj, for j=1,2,,k-1.
If the boundary values of the classes are to be function-calculated, then they are determined in one of the following ways:
  1. (a)if k>2, the range of x values is divided into k-2 intervals of equal length, and two extreme intervals, defined by the class boundary values y1,y2,,yk-1;
  2. (b)if k=2, y1=12(a+b).
However formed, the values y1,,yk-1 are assumed to be in ascending order. The class frequencies are formed with where [ means inclusive, and ) means exclusive. If the class boundary values are function-calculated and k>2, then f1=fk=0, and y1 and yk-1 are chosen so that y1<a and yk-1>b.
If a frequency distribution is required for a discrete variable, then it is suggested that you supply the class boundary values; function-calculated boundary values may be slightly imprecise (due to the adjustment of y1 and yk-1 outlined above) and cause values very close to a class boundary to be assigned to the wrong class.

4 References

None.

5 Arguments

1: n Integer Input
On entry: n, the number of observations.
Constraint: n1.
2: x[n] const double Input
On entry: the sample of observations of the variable for which the frequency distribution is required, xi, for i=1,2,,n. The values may be in any order.
3: num_class Integer Input
On entry: k, the number of classes desired in the frequency distribution. Whether or not class boundary values are user-supplied, num_class must include the two extreme classes which stretch to ±.
Constraint: num_class2.
4: classb Nag_ClassBoundary Input
On entry: indicates whether class boundary values are to be calculated within g01aec, or are supplied by you.
If classb=Nag_ClassBoundaryComp, the class boundary values are to be calculated within the function.
If classb=Nag_ClassBoundaryUser, they are user-supplied.
Constraint: classb=Nag_ClassBoundaryComp or Nag_ClassBoundaryUser.
5: cint[num_class] double Input/Output
On entry: if classb=Nag_ClassBoundaryComp, the elements of cint need not be assigned values, as g01aec calculates k-1 class boundary values.
If classb=Nag_ClassBoundaryUser, the first k-1 elements of cint must contain the class boundary values you supplied, in ascending order.
On exit: the first k-1 elements of cint contain the class boundary values in ascending order.
Constraint: if classb=Nag_ClassBoundaryUser, cint[i-1]<cint[i], for i=1,2,,k-2.
6: ifreq[num_class] Integer Output
On exit: the elements of ifreq contain the frequencies in each class, fi, for i=1,2,,k. In particular ifreq[0] contains the frequency of the class up to cint[0], f1, and ifreq[k-1] contains the frequency of the class greater than cint[k-2], fk.
7: xmin double * Output
On exit: the smallest value in the sample, a.
8: xmax double * Output
On exit: the largest value in the sample, b.
9: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT_ARG_LT
On entry, n=value.
Constraint: n1.
On entry, num_class=value.
Constraint: num_class2.
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_STRICTLY_INCREASING
On entry, cint[value]=value and cint[value]=value.
Constraint: cint[value]<cint[value].

7 Accuracy

The method used is believed to be stable.

8 Parallelism and Performance

g01aec is not threaded in any implementation.

9 Further Comments

The time taken by g01aec increases with num_class and n. It also depends on the distribution of the sample observations.

10 Example

This example summarises a number of datasets. For each dataset the sample observations and optionally class boundary values are read. g01aec is then called and the frequency distribution and largest and smallest observations printed.

10.1 Program Text

Program Text (g01aece.c)

10.2 Program Data

Program Data (g01aece.d)

10.3 Program Results

Program Results (g01aece.r)