# NAG FL Interfaceg03ehf (cluster_​hier_​dendrogram)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g03ehf produces a dendrogram from the results of g03ecf.

## 2Specification

Fortran Interface
 Subroutine g03ehf ( n, dord, dmin, nsym, c, lenc,
 Integer, Intent (In) :: n, nsym, lenc Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: dord(n), dmin, dstep Character (*), Intent (Out) :: c(lenc) Character (1), Intent (In) :: orient
#include <nag.h>
 void g03ehf_ (const char *orient, const Integer *n, const double dord[], const double *dmin, const double *dstep, const Integer *nsym, char c[], const Integer *lenc, Integer *ifail, const Charlen length_orient, const Charlen length_c)
The routine may be called by the names g03ehf or nagf_mv_cluster_hier_dendrogram.

## 3Description

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,
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.

## 4References

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

## 5Arguments

1: $\mathbf{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: $\mathbf{n}$Integer Input
On entry: the number of objects in the cluster analysis.
Constraint: ${\mathbf{n}}>2$.
3: $\mathbf{dord}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{dmin}$Real (Kind=nag_wp) Input
On entry: the clustering distance at which the dendrogram begins.
Constraint: ${\mathbf{dmin}}\ge 0.0$.
5: $\mathbf{dstep}$Real (Kind=nag_wp) Input
On entry: the distance represented by one symbol of the dendrogram.
Constraint: ${\mathbf{dstep}}>0.0$.
6: $\mathbf{nsym}$Integer Input
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: $\mathbf{c}\left({\mathbf{lenc}}\right)$Character(*) array Output
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: $\mathbf{lenc}$Integer Input
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: $\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{dmin}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{dmin}}\ge 0.0$.
On entry, ${\mathbf{dstep}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{dstep}}>0.0$.
On entry, ${\mathbf{lenc}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{orient}}=\text{'E'}$ or $\text{'W'}$.
Constraint: if ${\mathbf{orient}}=\text{'E'}$ or $\text{'W'}$, ${\mathbf{lenc}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{lenc}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{orient}}=\text{'N'}$ or $\text{'S'}$.
Constraint: if ${\mathbf{orient}}=\text{'N'}$ or $\text{'S'}$, ${\mathbf{lenc}}\ge {\mathbf{nsym}}$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>2$.
On entry, ${\mathbf{nsym}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nsym}}\ge 1$.
On entry, ${\mathbf{orient}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{orient}}=\text{'N'}$, $\text{'S'}$, $\text{'E'}$ or $\text{'W'}$.
On entry, the number of characters that can be stored in each element of c is insufficient for the requested orientation.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{dord}}\left(i\right)>{\mathbf{dord}}\left({\mathbf{n}}\right)$, $i<{\mathbf{n}}$.
${\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.

Not applicable.

## 8Parallelism and Performance

g03ehf is not threaded in any implementation.

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.

## 10Example

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.

### 10.1Program Text

Program Text (g03ehfe.f90)

### 10.2Program Data

Program Data (g03ehfe.d)

### 10.3Program Results

Program Results (g03ehfe.r)