G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG03EHF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G03EHF produces a dendrogram from the results of G03ECF.

## 2  Specification

 SUBROUTINE G03EHF ( ORIENT, N, DORD, DMIN, DSTEP, NSYM, C, LENC, IFAIL)
 INTEGER N, NSYM, LENC, IFAIL REAL (KIND=nag_wp) DORD(N), DMIN, DSTEP CHARACTER(*) C(LENC) CHARACTER(1) ORIENT

## 3  Description

Hierarchical cluster analysis, as performed by G03ECF, can be represented by a tree that shows at which distance the clusters merge. Such a tree is known as a dendrogram. See Everitt (1974) and Krzanowski (1990) for examples of dendrograms. A simple example is,
Figure 1
The end points of the dendrogram represent the objects that have been clustered. They should be in a suitable order as given by G03ECF. Object $1$ is always the first object. In the example above the height represents the distance at which the clusters merge.
The dendrogram is produced in a character array using the ordering and distances provided by G03ECF. Suitable characters are used to represent parts of the tree.
There are four possible orientations for the dendrogram. The example above has the end points at the bottom of the diagram which will be referred to as south. If the dendrogram was the other way around with the end points at the top of the diagram then the orientation would be north. If the end points are at the left-hand or right-hand side of the diagram the orientation is west or east. Different symbols are used for east/west and north/south orientations.

## 4  References

Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press

## 5  Parameters

1:     ORIENT – CHARACTER(1)Input
On entry: indicates which orientation the dendrogram is to take.
${\mathbf{ORIENT}}=\text{'N'}$
The end points of the dendrogram are to the north.
${\mathbf{ORIENT}}=\text{'S'}$
The end points of the dendrogram are to the south.
${\mathbf{ORIENT}}=\text{'E'}$
The end points of the dendrogram are to the east.
${\mathbf{ORIENT}}=\text{'W'}$
The end points of the dendrogram are to the west.
Constraint: ${\mathbf{ORIENT}}=\text{'N'}$, $\text{'S'}$, $\text{'E'}$ or $\text{'W'}$.
2:     N – INTEGERInput
On entry: the number of objects in the cluster analysis.
Constraint: ${\mathbf{N}}>2$.
3:     DORD(N) – REAL (KIND=nag_wp) arrayInput
On entry: the array DORD as output by G03ECF. DORD contains the distances, in dendrogram order, at which clustering takes place.
Constraint: ${\mathbf{DORD}}\left({\mathbf{N}}\right)\ge {\mathbf{DORD}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}-1$.
4:     DMIN – REAL (KIND=nag_wp)Input
On entry: the clustering distance at which the dendrogram begins.
Constraint: ${\mathbf{DMIN}}\ge 0.0$.
5:     DSTEP – REAL (KIND=nag_wp)Input
On entry: the distance represented by one symbol of the dendrogram.
Constraint: ${\mathbf{DSTEP}}>0.0$.
6:     NSYM – INTEGERInput
On entry: the number of character positions used in the dendrogram. Hence the clustering distance at which the dendrogram terminates is given by ${\mathbf{DMIN}}+{\mathbf{NSYM}}×{\mathbf{DSTEP}}$.
Constraint: ${\mathbf{NSYM}}\ge 1$.
7:     C(LENC) – CHARACTER(*) arrayOutput
Note:  the length of each element of C must be at least $3×{\mathbf{N}}$ if ${\mathbf{ORIENT}}=\text{'N'}$ or $\text{'S'}$, or at least NSYM if ${\mathbf{ORIENT}}=\text{'E'}$ or $\text{'W'}$.
On exit: the elements of C contain consecutive lines of the dendrogram.
8:     LENC – INTEGERInput
On entry: the dimension of the array C as declared in the (sub)program from which G03EHF is called.
Constraints:
• if ${\mathbf{ORIENT}}=\text{'N'}$ or $\text{'S'}$, ${\mathbf{LENC}}\ge {\mathbf{NSYM}}$;
• if ${\mathbf{ORIENT}}=\text{'E'}$ or $\text{'W'}$, ${\mathbf{LENC}}\ge {\mathbf{N}}$.
9:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ 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 parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{N}}\le 2$, or ${\mathbf{NSYM}}<1$, or ${\mathbf{DMIN}}<0.0$, or ${\mathbf{DSTEP}}\le 0.0$, or ${\mathbf{ORIENT}}\ne \text{'N'},\text{'S'},\text{'E'}$, or 'W', or ${\mathbf{ORIENT}}=\text{'N'}$ or $\text{'S'}$, ${\mathbf{LENC}}<{\mathbf{NSYM}}$, or ${\mathbf{ORIENT}}=\text{'E'}$ or $\text{'W'}$, ${\mathbf{LENC}}<{\mathbf{N}}$, or the number of characters that can be stored in each element of array C is insufficient for the requested orientation.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{DORD}}\left({\mathbf{N}}\right)<{\mathbf{DORD}}\left(i\right)$, for some $i=1,2,\dots ,{\mathbf{N}}-1$.

## 7  Accuracy

Not applicable.

The scale of the dendrogram is controlled by DSTEP. The smaller the value DSTEP is, the greater the amount of detail that will be given but NSYM will have to be larger to give the full dendrogram. The range of distances represented by the dendrogram is DMIN to ${\mathbf{NSYM}}×{\mathbf{DSTEP}}$. The values of DMIN, DSTEP and NSYM can thus be set so that only part of the dendrogram is produced.
The dendrogram does not include any labelling of the objects. You can print suitable labels using the ordering given by the array IORD returned by G03ECF.

## 9  Example

Data consisting of three variables on five objects are read in. Euclidean squared distances are computed using G03EAF and median clustering performed by G03ECF. G03EHF is used to produce a dendrogram with orientation east and a dendrogram with orientation south. The two dendrograms are printed.

### 9.1  Program Text

Program Text (g03ehfe.f90)

### 9.2  Program Data

Program Data (g03ehfe.d)

### 9.3  Program Results

Program Results (g03ehfe.r)