NAG CL Interface
g03fac (multidimscal_​metric)

Settings help

CL Name Style:

1 Purpose

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

2 Specification

#include <nag.h>
void  g03fac (Nag_Eigenvalues roots, Integer n, const double d[], Integer ndim, double x[], Integer tdx, double eval[], NagError *fail)
The function may be called by the names: g03fac, nag_mv_multidimscal_metric or nag_mv_prin_coord_analysis.

3 Description

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 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. g03fac provides the option for all eigenvalues to be computed so that the smallest eigenvalues can be checked.

4 References

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

5 Arguments

1: roots Nag_Eigenvalues Input
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 Integer Input
On entry: the number of objects in the distance matrix, n .
Constraint: n>ndim .
3: d[n×(n-1)/2] const double Input
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 Integer Input
On entry: the number of dimensions used to represent the data, k .
Constraint: ndim1 .
5: x[n×tdx] double Output
Note: the (i,j)th 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 Integer Input
On entry: the stride separating matrix column elements in the array x.
Constraint: tdxndim .
7: eval[n] double Output
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 7 in the Introduction to the NAG Library CL Interface).

6 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 (g03fcc).
On entry, d[value] = value.
Constraint: d[i-1] 0.0 , for i=1,2,,n × (n-1) / 2.

7 Accuracy

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

8 Parallelism and Performance

g03fac is not threaded in any implementation.

9 Further Comments


10 Example

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

10.1 Program Text

Program Text (g03face.c)

10.2 Program Data

Program Data (g03face.d)

10.3 Program Results

Program Results (g03face.r)