G03EJF (PDF version)
G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G03EJF

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.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G03EJF computes a cluster indicator variable from the results of G03ECF.

2  Specification

SUBROUTINE G03EJF ( N, CD, IORD, DORD, K, DLEVEL, IC, IFAIL)
INTEGER  N, IORD(N), K, IC(N), IFAIL
REAL (KIND=nag_wp)  CD(N-1), DORD(N), DLEVEL

3  Description

Given a distance or dissimilarity matrix for n objects, cluster analysis aims to group the n objects into a number of more or less homogeneous groups or clusters. With agglomerative clustering methods (see G03ECF), a hierarchical tree is produced by starting with n clusters each with a single object and then at each of n-1 stages, merging two clusters to form a larger cluster until all objects are in a single cluster. G03EJF takes the information from the tree and produces the clusters that exist at a given distance. This is equivalent to taking the dendrogram (see G03EHF) and drawing a line across at a given distance to produce clusters.
As an alternative to giving the distance at which clusters are required, you can specify the number of clusters required and G03EJF will compute the corresponding distance. However, it may not be possible to compute the number of clusters required due to ties in the distance matrix.
If there are k clusters then the indicator variable will assign a value between 1 and k to each object to indicate to which cluster it belongs. Object 1 always belongs to cluster 1.

4  References

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

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of objects.
Constraint: N2.
2:     CDN-1 – REAL (KIND=nag_wp) arrayInput
On entry: the clustering distances in increasing order as returned by G03ECF.
Constraint: CDi+1CDi, for i=1,2,,N-2.
3:     IORDN – INTEGER arrayInput
On entry: the objects in dendrogram order as returned by G03ECF.
4:     DORDN – REAL (KIND=nag_wp) arrayInput
On entry: the clustering distances corresponding to the order in IORD.
5:     K – INTEGERInput/Output
On entry: indicates if a specified number of clusters is required.
If K>0 then G03EJF will attempt to find K clusters.
If K0 then G03EJF will find the clusters based on the distance given in DLEVEL.
Constraint: KN.
On exit: the number of clusters produced, k.
6:     DLEVEL – REAL (KIND=nag_wp)Input/Output
On entry: if K0, DLEVEL must contain the distance at which clusters are produced. Otherwise DLEVEL need not be set.
Constraint: if DLEVEL>0.0, K0.
On exit: if K>0 on entry, DLEVEL contains the distance at which the required number of clusters are found. Otherwise DLEVEL remains unchanged.
7:     ICN – INTEGER arrayOutput
On exit: ICi indicates to which of k clusters the ith object belongs, for i=1,2,,n.
8:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ 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​ 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 -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
IFAIL=1
On entry,K>N,
orK0 and DLEVEL0.0.
orN<2.
IFAIL=2
On entry,CD is not in increasing order,
orDORD is incompatible with CD.
IFAIL=3
On entry,K=1,
orK=N,
orDLEVELCDN-1,
orDLEVEL<CD1.
Note:  on exit with this value of IFAIL the trivial clustering solution is returned.
IFAIL=4
The precise number of clusters requested is not possible because of tied clustering distances. The actual number of clusters, less than the number requested, is returned in K.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The accuracy will depend upon the accuracy of the distances in CD and DORD (see G03ECF).

8  Parallelism and Performance

Not applicable.

9  Further Comments

A fixed number of clusters can be found using the non-hierarchical method used in G03EFF.

10  Example

Data consisting of three variables on five objects are input. Euclidean squared distances are computed using G03EAF and median clustering performed using G03ECF. A dendrogram is produced by G03EHF and printed. G03EJF finds two clusters and the results are printed.

10.1  Program Text

Program Text (g03ejfe.f90)

10.2  Program Data

Program Data (g03ejfe.d)

10.3  Program Results

Program Results (g03ejfe.r)


G03EJF (PDF version)
G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015