Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_mv_cluster_hier_dendrogram (g03eh)

## Purpose

nag_mv_cluster_hier_dendrogram (g03eh) produces a dendrogram from the results of nag_mv_cluster_hier (g03ec).

## Syntax

[c, ifail] = g03eh(orient, dord, dmin, dstep, nsym, lenc, 'n', n)
[c, ifail] = nag_mv_cluster_hier_dendrogram(orient, dord, dmin, dstep, nsym, lenc, 'n', n)

## Description

Hierarchical cluster analysis, as performed by nag_mv_cluster_hier (g03ec), 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 nag_mv_cluster_hier (g03ec). Object 1$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 nag_mv_cluster_hier (g03ec). 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.

## References

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

## Parameters

### Compulsory Input Parameters

1:     orient – string (length ≥ 1)
Indicates which orientation the dendrogram is to take.
orient = 'N'${\mathbf{orient}}=\text{'N'}$
The end points of the dendrogram are to the north.
orient = 'S'${\mathbf{orient}}=\text{'S'}$
The end points of the dendrogram are to the south.
orient = 'E'${\mathbf{orient}}=\text{'E'}$
The end points of the dendrogram are to the east.
orient = 'W'${\mathbf{orient}}=\text{'W'}$
The end points of the dendrogram are to the west.
Constraint: orient = 'N'${\mathbf{orient}}=\text{'N'}$, 'S'$\text{'S'}$, 'E'$\text{'E'}$ or 'W'$\text{'W'}$.
2:     dord(n) – double array
n, the dimension of the array, must satisfy the constraint n > 2${\mathbf{n}}>2$.
The array dord as output by nag_mv_cluster_hier (g03ec). dord contains the distances, in dendrogram order, at which clustering takes place.
Constraint: dord(n)dord(i)${\mathbf{dord}}\left({\mathbf{n}}\right)\ge {\mathbf{dord}}\left(\mathit{i}\right)$, for i = 1,2,,n1$\mathit{i}=1,2,\dots ,{\mathbf{n}}-1$.
3:     dmin – double scalar
The clustering distance at which the dendrogram begins.
Constraint: dmin0.0${\mathbf{dmin}}\ge 0.0$.
4:     dstep – double scalar
The distance represented by one symbol of the dendrogram.
Constraint: dstep > 0.0${\mathbf{dstep}}>0.0$.
5:     nsym – int64int32nag_int scalar
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: nsym1${\mathbf{nsym}}\ge 1$.
6:     lenc – int64int32nag_int scalar
The dimension of the array c as declared in the (sub)program from which nag_mv_cluster_hier_dendrogram (g03eh) is called.
Constraints:
• if orient = 'N'${\mathbf{orient}}=\text{'N'}$ or 'S'$\text{'S'}$, ${\mathbf{lenc}}\ge {\mathbf{nsym}}$;
• if orient = 'E'${\mathbf{orient}}=\text{'E'}$ or 'W'$\text{'W'}$, ${\mathbf{lenc}}\ge {\mathbf{n}}$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array dord.
The number of objects in the cluster analysis.
Constraint: n > 2${\mathbf{n}}>2$.

None.

### Output Parameters

1:     c(lenc) – cell array of strings
The elements of c contain consecutive lines of the dendrogram.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n ≤ 2${\mathbf{n}}\le 2$, or nsym < 1${\mathbf{nsym}}<1$, or dmin < 0.0${\mathbf{dmin}}<0.0$, or dstep ≤ 0.0${\mathbf{dstep}}\le 0.0$, or orient ≠ 'N','S','E'${\mathbf{orient}}\ne \text{'N'},\text{'S'},\text{'E'}$, or 'W', or orient = 'N'${\mathbf{orient}}=\text{'N'}$ or 'S'$\text{'S'}$, ${\mathbf{lenc}}<{\mathbf{nsym}}$, or orient = 'E'${\mathbf{orient}}=\text{'E'}$ or 'W'$\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.
ifail = 2${\mathbf{ifail}}=2$
 On entry, dord(n) < dord(i)${\mathbf{dord}}\left({\mathbf{n}}\right)<{\mathbf{dord}}\left(i\right)$, for some i = 1,2, … ,n − 1$i=1,2,\dots ,{\mathbf{n}}-1$.

## 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 nag_mv_cluster_hier (g03ec).

## Example

```function nag_mv_cluster_hier_dendrogram_example
orient = 'E';
dord = [1;
36.25;
8;
4;
36.25];
dmin = 0;
dstep = 1.1;
nsym = int64(40);
lenc = int64(100);

[c, ifail] = nag_mv_cluster_hier_dendrogram(orient, dord, dmin, dstep, nsym, lenc)
```
```

c =

'                                        '
'        ...............................('
'       (                         .......'
'       (                        (    ...'
'       (........................(...(...'
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '

ifail =

0

```
```function g03eh_example
orient = 'E';
dord = [1;
36.25;
8;
4;
36.25];
dmin = 0;
dstep = 1.1;
nsym = int64(40);
lenc = int64(100);

[c, ifail] = g03eh(orient, dord, dmin, dstep, nsym, lenc)
```
```

c =

'                                        '
'        ...............................('
'       (                         .......'
'       (                        (    ...'
'       (........................(...(...'
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '
'                                        '

ifail =

0

```