​metric, n, d, ndim)[source]

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

For full information please refer to the NAG Library document for g03fa

rootsstr, length 1

Indicates if all the eigenvalues are to be computed or just the largest.

All the eigenvalues are computed.

Only the largest eigenvalues are computed.


, the number of objects in the distance matrix.

dfloat, array-like, shape

The lower triangle of the distance matrix stored packed by rows. That is must contain for .


, the number of dimensions used to represent the data.

xfloat, ndarray, shape

The th row contains coordinates for the th point, .

eigvalfloat, ndarray, shape

If , contains the scaled eigenvalues of the matrix .

If , contains the largest scaled eigenvalues of the matrix .

In both cases the eigenvalues are divided by the sum of the eigenvalues (that is, the trace of ).

(errno )

On entry, .

Constraint: or .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, all the elements of .

(errno )

On entry, and .

Constraint: .

(errno )

There are less than eigenvalues greater than zero.

(errno )

The computation of the eigenvalues or eigenvectors has failed.


In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

For a set of objects a distance matrix can be calculated such that is a measure of how ‘far apart’ are objects and (see distance_mat() for example). Principal coordinate analysis or metric scaling starts with a distance matrix and finds points in Euclidean space such that those points have the same distance matrix. The aim is to find a small number of dimensions, , that provide an adequate representation of the distances.

The principal coordinates of the points are computed from the eigenvectors of the matrix where with denoting the average of over the suffix , etc.. The eigenvectors are then scaled by multiplying by the square root of the value of the corresponding eigenvalue.

Provided that the ordered eigenvalues, , of the matrix are all positive, shows how well the data is represented in dimensions. The eigenvalues will be non-negative if is positive semidefinite. This will be true provided satisfies the inequality: for all . 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. multidimscal_metric 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