g03 Chapter Contents
g03 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_mv_ordinal_multidimscale (g03fcc)

## 1  Purpose

nag_mv_ordinal_multidimscale (g03fcc) performs non-metric (ordinal) multidimensional scaling.

## 2  Specification

 #include #include
 void nag_mv_ordinal_multidimscale (Nag_ScaleCriterion type, Integer n, Integer ndim, const double d[], double x[], Integer tdx, double *stress, double dfit[], Nag_E04_Opt *options, NagError *fail)

## 3  Description

For a set of $n$ objects, a distance or dissimilarity matrix $D$ can be calculated such that ${d}_{ij}$ is a measure of how ‘far apart’ objects $i$ and $j$ are. If $p$ variables ${x}_{k}$ have been recorded for each observation this measure may be based on Euclidean distance, ${d}_{ij}={\sum }_{k=1}^{p}{\left({x}_{ki}-{x}_{kj}\right)}^{2}$, or some other calculation such as the number of variables for which ${x}_{kj}\ne {x}_{ki}$. Alternatively, the distances may be the result of a subjective assessment. For a given distance matrix, multidimensional scaling produces a configuration of $n$ points in a chosen number of dimensions, $m$, such that the distance between the points in some way best matches the distance matrix. For some distance measures, such as Euclidean distance, the size of distance is meaningful, for other measures of distance all that can be said is that one distance is greater or smaller than another. For the former, metric scaling can be used, see nag_mv_prin_coord_analysis (g03fac), for the latter, a non-metric scaling is more appropriate.
For non-metric multidimensional scaling, the criterion used to measure the closeness of the fitted distance matrix to the observed distance matrix is known as $\mathit{stress}$. $\mathit{stress}$ is given by,
 $∑ i=1 n ∑ j=1 i-1 d ^ ij - d ~ ij 2 ∑ i=1 n ∑ j=1 i-1 d ^ ij 2$
where ${\stackrel{^}{d}}_{ij}^{2}$ is the Euclidean squared distance between points $i$ and $j$ and ${\stackrel{~}{d}}_{ij}$ is the fitted distance obtained when ${\stackrel{^}{d}}_{ij}$ is monotonically regressed on ${d}_{ij}$, that is, ${\stackrel{~}{d}}_{ij}$ is monotonic relative to ${d}_{ij}$ and is obtained from ${\stackrel{^}{d}}_{ij}$ with the smallest number of changes. So $\mathit{stress}$ is a measure of by how much the set of points preserve the order of the distances in the original distance matrix. Non-metric multidimensional scaling seeks to find the set of points that minimize the $\mathit{stress}$.
An alternate measure is squared $\mathit{stress}$, $SSTRESS$,
 $∑ i=1 n ∑ j=1 i-1 d ^ ij 2 - d ~ ij 2 2 ∑ i=1 n ∑ j=1 i-1 d ^ ij 4$
in which the distances in $\mathit{stress}$ are replaced by squared distances.
In order to perform a non-metric scaling, an initial configuration of points is required. This can be obtained from principal coordinate analysis, see nag_mv_prin_coord_analysis (g03fac). Given an initial configuration, nag_mv_ordinal_multidimscale (g03fcc) uses the optimization function nag_opt_conj_grad (e04dgc) to find the configuration of points that minimizes $\mathit{stress}$ or $SSTRESS$. The function nag_opt_conj_grad (e04dgc) uses a conjugate gradient algorithm. nag_mv_ordinal_multidimscale (g03fcc) will find an optimum that may only be a local optimum, to be more sure of finding a global optimum several different initial configurations should be used; these can be obtained by randomly perturbing the original initial configuration using functions from the g05 Chapter Introduction.

## 4  References

Chatfield C and Collins A J (1980) Introduction to Multivariate Analysis Chapman and Hall
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press

## 5  Arguments

1:     typeNag_ScaleCriterionInput
On entry: indicates whether $\mathit{stress}$ or $SSTRESS$ is to be used as the criterion.
${\mathbf{type}}=\mathrm{Nag_Stress}$
$\mathit{stress}$ is used.
${\mathbf{type}}=\mathrm{Nag_SStress}$
$SSTRESS$ is used.
Constraint: ${\mathbf{type}}=\mathrm{Nag_Stress}$ or $\mathrm{Nag_SStress}$.
2:     nIntegerInput
On entry: the number of objects in the distance matrix , $n$.
Constraint: ${\mathbf{n}}>{\mathbf{ndim}}$.
3:     ndimIntegerInput
On entry: the number of dimensions used to represent the data, $m$.
Constraint: ${\mathbf{ndim}}\ge 1$.
4:     d[${\mathbf{n}}×\left({\mathbf{n}}-1\right)/2$]const doubleInput
On entry: the lower triangle of the distance matrix $D$ stored packed by rows. That is ${\mathbf{d}}\left[\left(\mathit{i}-1\right)×\left(i-2\right)/2+\mathit{j}-1\right]$ must contain ${d}_{\mathit{i}\mathit{j}}$, for $\mathit{i}=2,3,\dots ,n$ and $\mathit{j}=1,2,\dots ,i-1$. If ${d}_{ij}$ is missing then set ${d}_{ij}<0$; For further comments on missing values see Section 8.
5:     x[${\mathbf{n}}×{\mathbf{tdx}}$]doubleInput/Output
Note: the $\left(i,j\right)$th element of the matrix $X$ is stored in ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{tdx}}+j-1\right]$.
On entry: the $i$th row must contain an initial estimate of the coordinates for the $i$th point, $i=1,2,\dots ,n$. One method of computing these is to use nag_mv_prin_coord_analysis (g03fac).
On exit: the $i$th row contains $m$ coordinates for the $i$th point, $i=1,2,\dots ,n$.
6:     tdxIntegerInput
On entry: the stride separating matrix column elements in the array x.
Constraint: ${\mathbf{tdx}}\ge {\mathbf{ndim}}$.
7:     stressdouble *Output
On exit: the value of $\mathit{stress}$ or $SSTRESS$ at the final iteration.
8:     dfit[$2×{\mathbf{n}}×\left({\mathbf{n}}-1\right)$]doubleOutput
On exit: auxiliary outputs. If ${\mathbf{type}}=\mathrm{Nag_Stress}$, the first $n\left(n-1\right)/2$ elements contain the distances, ${\stackrel{^}{d}}_{ij}$, for the points returned in x, the second set of $n\left(n-1\right)/2$ contains the distances ${\stackrel{^}{d}}_{ij}$ ordered by the input distances, ${d}_{ij}$, the third set of $n\left(n-1\right)/2$ elements contains the monotonic distances, ${\stackrel{~}{d}}_{ij}$, ordered by the input distances, ${d}_{ij}$ and the final set of $n\left(n-1\right)/2$ elements contains fitted monotonic distances, ${\stackrel{~}{d}}_{ij}$, for the points in x. The ${\stackrel{~}{d}}_{ij}$ corresponding to distances which are input as missing are set to zero. If ${\mathbf{type}}=\mathrm{Nag_SStress}$, the results are as above except that the squared distances are returned.
Each distance matrix is stored in lower triangular packed form in the same way as the input matrix $D$.
9:     optionsNag_E04_Opt *Input/Output
On entry/exit: a pointer to a structure of type Nag_E04_Opt whose members are optional arguments for nag_opt_conj_grad (e04dgc). These structure members offer the means of adjusting some of the argument values of the algorithm and on output will supply further details of the results. You are referred to the nag_opt_conj_grad (e04dgc) document for further details.
The default values used by nag_mv_ordinal_multidimscale (g03fcc) when the options argument is set to the NAG defined null pointer, E04_DEFAULT, are as follows:
• ${\mathbf{optim_tol}}=0.00001$;
• ${\mathbf{print_level}}=\mathrm{Nag_NoPrint}$;
• ${\mathbf{list}}=\mathrm{Nag_FALSE}$;
• ${\mathbf{verify_grad}}=\mathrm{Nag_FALSE}$;
• ${\mathbf{max_iter}}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,{\mathbf{n}}×{\mathbf{ndim}}\right)$.
If a different value is required for any of these four structure members or if other options available in nag_opt_conj_grad (e04dgc) are to be used, then the structure options should be declared and initialized by a call to nag_opt_init (e04xxc) and supplied as an argument to nag_mv_ordinal_multidimscale (g03fcc). In this case, the structure members listed above except for ${\mathbf{list}}$ will have the default values as specified above; ${\mathbf{list}}=\mathrm{Nag_TRUE}$ in this case.
10:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LE
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{n}}>{\mathbf{ndim}}$.
NE_2_INT_ARG_LT
On entry, ${\mathbf{tdx}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{tdx}}\ge {\mathbf{ndim}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument type had an illegal value.
NE_INT_ARG_LT
On entry, ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ndim}}\ge 1$.
NE_INTERNAL_ERROR
Additional error messages are output if the optimization fails to converge or if the options are set incorrectly, Details of these can be found in the nag_opt_conj_grad (e04dgc) document.
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.
NE_NEG_OR_ZERO_ARRAY
All elements of array ${\mathbf{d}}\le 0.0$.
Constraint: At least one element of d must be positive.

## 7  Accuracy

After a successful optimization, the relative accuracy of $\mathit{stress}$ should be approximately $\epsilon$, as specified by ${\mathbf{optim_tol}}$.

## 8  Further Comments

Missing values in the input distance matrix can be specified by a negative value and providing there are not more than about two thirds of the values missing, the algorithm may still work. However, the function nag_mv_prin_coord_analysis (g03fac) does not allow for missing values so an alternative method of obtaining an initial set of coordinates is required. It may be possible to estimate the missing values with some form of average and then use nag_mv_prin_coord_analysis (g03fac) to give an initial set of coordinates.

## 9  Example

The data, given by Krzanowski (1990), are dissimilarities between water vole populations in Europe. Initial estimates are provided by the first two principal coordinates computed by nag_mv_prin_coord_analysis (g03fac). The two dimension solution is computed using nag_mv_ordinal_multidimscale (g03fcc).

### 9.1  Program Text

Program Text (g03fcce.c)

### 9.2  Program Data

Program Data (g03fcce.d)

### 9.3  Program Results

Program Results (g03fcce.r)