NAG C Library Function Document

nag_mv_prin_coord_analysis (g03fac)


nag_mv_prin_coord_analysis (g03fac) performs a principal coordinate analysis also known as classical metric scaling.


#include <nag.h>
#include <nagg03.h>
void  nag_mv_prin_coord_analysis (Nag_Eigenvalues roots, Integer n, const double d[], Integer ndim, double x[], Integer tdx, double eval[], NagError *fail)


For a set of n  objects, a distance matrix D  can be calculated such that d ij  is a measure of how ‘far apart’ objects i  and j  are (see nag_mv_distance_mat (g03eac) for example). Principal coordinate analysis or metric scaling starts with a distance matrix and finds points X  in Euclidean space such that those points have the same distance matrix. The aim is to find a small number of dimensions, k < < n-1 , that provide an adequate representation of the distances.
The principal coordinates of the points are computed from the eigenvectors of the matrix E  where e ij = - 1 2 d ij 2 - d i. 2 - d .j 2 - d .. 2  with d i 2  denoting the average of d ij 2  over the suffix j  etc.. The eigenvectors are then scaled by multiplying by the square root of the value of the corresponding eigenvalue.
Provided that the ordered eigenvalues, λ i , of the matrix E  are all positive, i=1 k λ i / i=1 n-1 λ i  shows how well the data is represented in k  dimensions. The eigenvalues will be non-negative if E  is positive semidefinite. This will be true provided d ij  satisfies the inequality: d ij d ik + d jk  for all i , j , k . If this is not the case the size of the negative eigenvalue reflects the amount of deviation from this condition and the results should be treated cautiously in the presence of large negative eigenvalues. See Krzanowski (1990) for further discussion. nag_mv_prin_coord_analysis (g03fac) provides the option for all eigenvalues to be computed so that the smallest eigenvalues can be checked.


Chatfield C and Collins A J (1980) Introduction to Multivariate Analysis Chapman and Hall
Gower J C (1966) Some distance properties of latent root and vector methods used in multivariate analysis Biometrika 53 325–338
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press


1:     roots Nag_EigenvaluesInput
On entry: indicates if all the eigenvalues are to be computed or just the ndim largest.
All the eigenvalues are computed.
Only the largest ndim eigenvalues are computed.
Constraint: roots=Nag_AllEigVals or Nag_LargeEigVals.
2:     n IntegerInput
On entry: the number of objects in the distance matrix, n .
Constraint: n>ndim .
3:     d[n×n-1/2] const doubleInput
On entry: the lower triangle of the distance matrix D  stored packed by rows. That is, d[ i-1 × i-2 / 2 + j - 1 ]  must contain d ij , for i=2,3,,n and j=1,2,,i-1.
Constraint: d[i-1] 0.0 , for i=1,2,, n n-1 / 2 .
4:     ndim IntegerInput
On entry: the number of dimensions used to represent the data, k .
Constraint: ndim1 .
5:     x[n×tdx] doubleOutput
Note: the i,jth element of the matrix X is stored in x[i-1×tdx+j-1].
On exit: the i th row contains k  coordinates for the i th point, i = 1 , 2 , , n .
6:     tdx IntegerInput
On entry: the stride separating matrix column elements in the array x.
Constraint: tdxndim .
7:     eval[n] doubleOutput
On exit: if roots=Nag_AllEigVals, eval contains the n  scaled eigenvalues of the matrix E . If roots=Nag_LargeEigVals, eval contains the largest k  scaled eigenvalues of the matrix E . In both cases the eigenvalues are divided by the sum of the eigenvalues (that is, the trace of E ).
8:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

On entry, n=value  while ndim=value . These arguments must satisfy n>ndim .
On entry, tdx=value  while ndim=value . These arguments must satisfy tdxndim .
Dynamic memory allocation failed.
On entry, argument roots had an illegal value.
The computation of eigenvalues or eigenvectors has failed.
On entry, ndim=value.
Constraint: ndim1.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
At least one element of the array d < 0.0.
Constraint: d[i-1] 0.0 , for i=1,2,,n × n-1 / 2.
There are fewer than ndim eigenvalues greater than zero. Try a smaller number of dimensions (ndim) or use non-metric scaling (nag_mv_ordinal_multidimscale (g03fcc)).
On entry, d[value] = value.
Constraint: d[i-1] 0.0 , for i=1,2,,n × n-1 / 2.


Alternative, non-metric, methods of scaling are provided by nag_mv_ordinal_multidimscale (g03fcc).
The relationship between principal coordinates and principal components (see nag_mv_ordinal_multidimscale (g03fcc)), is discussed in Krzanowski (1990) and Gower (1966).

Parallelism and Performance

nag_mv_prin_coord_analysis (g03fac) is not threaded in any implementation.

Further Comments



The data, given by Krzanowski (1990), are dissimilarities between water vole populations in Europe. The first two principal coordinates are computed.

Program Text

Program Text (g03face.c)

Program Data

Program Data (g03face.d)

Program Results

Program Results (g03face.r)