# NAG FL Interfaceg01aef (frequency_​table)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g01aef ( n, k, x, cb, xmin, xmax,
 Integer, Intent (In) :: n, k, iclass Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: ifreq(k) Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Inout) :: cb(k) Real (Kind=nag_wp), Intent (Out) :: xmin, xmax
#include <nag.h>
 void g01aef_ (const Integer *n, const Integer *k, const double x[], const Integer *iclass, double cb[], Integer ifreq[], double *xmin, double *xmax, Integer *ifail)
The routine may be called by the names g01aef or nagf_stat_frequency_table.

## 3Description

The data consists of a sample of $n$ observations of a continuous variable, denoted by ${x}_{i}$, for $\mathit{i}=1,2,\dots ,n$. Let $a=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({x}_{1},\dots ,{x}_{n}\right)$ and $b=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({x}_{1},\dots ,{x}_{n}\right)$.
g01aef constructs a frequency distribution with $k\left(>1\right)$ classes denoted by ${f}_{i}$, for $\mathit{i}=1,2,\dots ,k$.
The boundary values may be either user-supplied, or routine-calculated, and are denoted by ${y}_{j}$, for $\mathit{j}=1,2,\dots ,k-1$.
If the boundary values of the classes are to be routine-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 ${y}_{1},{y}_{2},\dots ,{y}_{k-1}$;
2. (b)if $k=2$, ${y}_{1}=\frac{1}{2}\left(a+b\right)$.
However formed, the values ${y}_{1},\dots ,{y}_{k-1}$ are assumed to be in ascending order. The class frequencies are formed with
• ${f}_{1}=\text{}$ the number of $x$ values in the interval $\left(-\infty ,{y}_{1}\right)$
• ${f}_{i}=\text{}$ the number of $x$ values in the interval $\left[{y}_{i-1},{y}_{i}\right)$, $\text{ }i=2,\dots ,k-1$
• ${f}_{k}=\text{}$ the number of $x$ values in the interval $\left[{y}_{k-1},\infty \right)$,
where [ means inclusive, and ) means exclusive. If the class boundary values are routine-calculated and $k>2$, then ${f}_{1}={f}_{k}=0$, and ${y}_{1}$ and ${y}_{k-1}$ are chosen so that ${y}_{1} and ${y}_{k-1}>b$.
If a frequency distribution is required for a discrete variable, then it is suggested that you supply the class boundary values; routine-calculated boundary values may be slightly imprecise (due to the adjustment of ${y}_{1}$ and ${y}_{k-1}$ outlined above) and cause values very close to a class boundary to be assigned to the wrong class.

None.

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{k}$Integer Input
On entry: $k$, the number of classes desired in the frequency distribution. Whether or not class boundary values are user-supplied, k must include the two extreme classes which stretch to $±\infty$.
Constraint: ${\mathbf{k}}\ge 2$.
3: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the sample of observations of the variable for which the frequency distribution is required, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$. The values may be in any order.
4: $\mathbf{iclass}$Integer Input
On entry: indicates whether class boundary values are to be calculated within g01aef, or are supplied by you.
If ${\mathbf{iclass}}=0$, the class boundary values are to be calculated within the routine.
If ${\mathbf{iclass}}=1$, they are user-supplied.
Constraint: ${\mathbf{iclass}}=0$ or $1$.
5: $\mathbf{cb}\left({\mathbf{k}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: if ${\mathbf{iclass}}=0$, the elements of cb need not be assigned values, as g01aef calculates $k-1$ class boundary values.
If ${\mathbf{iclass}}=1$, the first $k-1$ elements of cb must contain the class boundary values you supplied, in ascending order.
In both cases, the element ${\mathbf{cb}}\left(k\right)$ need not be assigned, as it is not used in the routine.
On exit: the first $k-1$ elements of cb contain the class boundary values in ascending order.
Constraint: if ${\mathbf{iclass}}=1$, ${\mathbf{cb}}\left(\mathit{i}\right)<{\mathbf{cb}}\left(\mathit{i}+1\right)$, for $\mathit{i}=1,2,\dots ,k-2$.
6: $\mathbf{ifreq}\left({\mathbf{k}}\right)$Integer array Output
On exit: the elements of ifreq contain the frequencies in each class, ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,k$. In particular ${\mathbf{ifreq}}\left(1\right)$ contains the frequency of the class up to ${\mathbf{cb}}\left(1\right)$, ${f}_{1}$, and ${\mathbf{ifreq}}\left(k\right)$ contains the frequency of the class greater than ${\mathbf{cb}}\left(k-1\right)$, ${f}_{k}$.
7: $\mathbf{xmin}$Real (Kind=nag_wp) Output
On exit: the smallest value in the sample, $a$.
8: $\mathbf{xmax}$Real (Kind=nag_wp) Output
On exit: the largest value in the sample, $b$.
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}}\ge 2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{cb}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{cb}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{cb}}\left(⟨\mathit{\text{value}}⟩\right)<{\mathbf{cb}}\left(⟨\mathit{\text{value}}⟩\right)$.
${\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

g01aef is not threaded in any implementation.

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

## 10Example

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

### 10.1Program Text

Program Text (g01aefe.f90)

### 10.2Program Data

Program Data (g01aefe.d)

### 10.3Program Results

Program Results (g01aefe.r)