Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_mv_multidimscal_ordinal (g03fc)

## Purpose

nag_mv_multidimscal_ordinal (g03fc) performs non-metric (ordinal) multidimensional scaling.

## Syntax

[x, stress, dfit, ifail] = g03fc(typ, d, x, iter, iopt, 'n', n, 'ndim', ndim)
[x, stress, dfit, ifail] = nag_mv_multidimscal_ordinal(typ, d, x, iter, iopt, 'n', n, 'ndim', ndim)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: n has been made optional
.

## Description

For a set of n$n$ objects, a distance or dissimilarity matrix D$D$ can be calculated such that dij${d}_{ij}$ is a measure of how ‘far apart’ the objects i$i$ and j$j$ are. If p$p$ variables xk${x}_{k}$ have been recorded for each observation this measure may be based on Euclidean distance, dij = k = 1p(xkixkj)2${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 xkjxki${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$n$ points in a chosen number of dimensions, m$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_multidimscal_metric (g03fa), 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 stress. stress is given by,
 sqrt( ( ∑ i = 1n ∑ j = 1i − 1(dij^ − dij~)2)/( ∑ i = 1n ∑ j = 1i − 1dij^2)) $∑i=1n∑j=1 i-1 (dij^-dij~) 2 ∑i=1n∑j=1 i-1dij^2$
where dij^2${\stackrel{^}{{d}_{ij}}}^{2}$ is the Euclidean squared distance between points i$i$ and j$j$ and dij~$\stackrel{~}{{d}_{ij}}$ is the fitted distance obtained when dij^$\stackrel{^}{{d}_{ij}}$ is monotonically regressed on dij${d}_{ij}$, that is dij~$\stackrel{~}{{d}_{ij}}$ is monotonic relative to dij${d}_{ij}$ and is obtained from dij^$\stackrel{^}{{d}_{ij}}$ with the smallest number of changes. So 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 stress.
An alternate measure is squared stress, sstress$\mathit{sstress}$,
 sqrt( ( ∑ i = 1n ∑ j = 1i − 1(dij^2 − dij~2)2)/( ∑ i = 1n ∑ j = 1i − 1dij^4)) $∑i=1n∑j=1 i-1 (dij^2-dij~2) 2 ∑i=1n∑j=1 i-1dij^4$
in which the distances in 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_multidimscal_metric (g03fa). Given an initial configuration, nag_mv_multidimscal_ordinal (g03fc) uses the optimization function nag_opt_uncon_conjgrd_comp (e04dg) to find the configuration of points that minimizes stress or sstress$\mathit{sstress}$. The function nag_opt_uncon_conjgrd_comp (e04dg) uses a conjugate gradient algorithm. nag_mv_multidimscal_ordinal (g03fc) 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 Chapter G05.

## 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

## Parameters

### Compulsory Input Parameters

1:     typ – string (length ≥ 1)
Indicates whether stress or sstress$\mathit{sstress}$ is to be used as the criterion.
typ = 'T'${\mathbf{typ}}=\text{'T'}$
stress is used.
typ = 'S'${\mathbf{typ}}=\text{'S'}$
sstress$\mathit{sstress}$ is used.
Constraint: typ = 'S'${\mathbf{typ}}=\text{'S'}$ or 'T'$\text{'T'}$.
2:     d(n × (n1) / 2${\mathbf{n}}×\left({\mathbf{n}}-1\right)/2$) – double array
The lower triangle of the distance matrix D$D$ stored packed by rows. That is d((i1) × (i2) / 2 + j)${\mathbf{d}}\left(\left(\mathit{i}-1\right)×\left(\mathit{i}-2\right)/2+\mathit{j}\right)$ must contain dij${d}_{\mathit{i}\mathit{j}}$, for i = 2,3,,n$\mathit{i}=2,3,\dots ,n$ and j = 1,2,,i1$\mathit{j}=1,2,\dots ,\mathit{i}-1$. If dij${d}_{ij}$ is missing then set dij < 0${d}_{ij}<0$; for further comments on missing values see Section [Further Comments].
3:     x(ldx,ndim) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxn$\mathit{ldx}\ge {\mathbf{n}}$.
The i$\mathit{i}$th row must contain an initial estimate of the coordinates for the i$\mathit{i}$th point, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$. One method of computing these is to use nag_mv_multidimscal_metric (g03fa).
4:     iter – int64int32nag_int scalar
The maximum number of iterations in the optimization process.
iter = 0${\mathbf{iter}}=0$
A default value of 50$50$ is used.
iter < 0${\mathbf{iter}}<0$
A default value of max (50,5nm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5nm\right)$ (the default for nag_opt_uncon_conjgrd_comp (e04dg)) is used.
5:     iopt – int64int32nag_int scalar
Selects the options, other than the number of iterations, that control the optimization.
iopt = 0${\mathbf{iopt}}=0$
Default values are selected as described in Section [Further Comments]. In particular if an accuracy requirement of ε = 0.00001$\epsilon =0.00001$ is selected, see Section [Accuracy].
iopt > 0${\mathbf{iopt}}>0$
The default values are used except that the accuracy is given by 10i${10}^{-i}$ where i = iopt$i={\mathbf{iopt}}$.
iopt < 0${\mathbf{iopt}}<0$
The option setting mechanism of nag_opt_uncon_conjgrd_comp (e04dg) can be used to set all options except Iteration Limit; this option is only recommended if you are an experienced user of NAG optimization functions. For further details see nag_opt_uncon_conjgrd_comp (e04dg).

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array d and the first dimension of the array x. (An error is raised if these dimensions are not equal.)
n$n$, the number of objects in the distance matrix.
Constraint: ${\mathbf{n}}>{\mathbf{ndim}}$.
2:     ndim – int64int32nag_int scalar
Default: The second dimension of the array x.
m$m$, the number of dimensions used to represent the data.
Constraint: ndim1${\mathbf{ndim}}\ge 1$.

ldx wk iwk

### Output Parameters

1:     x(ldx,ndim) – double array
ldxn$\mathit{ldx}\ge {\mathbf{n}}$.
The i$\mathit{i}$th row contains m$m$ coordinates for the i$\mathit{i}$th point, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     stress – double scalar
The value of stress or sstress$\mathit{sstress}$ at the final iteration.
3:     dfit(2 × n × (n1)$2×{\mathbf{n}}×\left({\mathbf{n}}-1\right)$) – double array
Auxiliary outputs.
If typ = 'T'${\mathbf{typ}}=\text{'T'}$, the first n(n1) / 2$n\left(n-1\right)/2$ elements contain the distances, dij^$\stackrel{^}{{d}_{ij}}$, for the points returned in x, the second set of n(n1) / 2$n\left(n-1\right)/2$ contains the distances dij^$\stackrel{^}{{d}_{ij}}$ ordered by the input distances, dij${d}_{ij}$, the third set of n(n1) / 2$n\left(n-1\right)/2$ elements contains the monotonic distances, dij~$\stackrel{~}{{d}_{ij}}$, ordered by the input distances, dij${d}_{ij}$ and the final set of n(n1) / 2$n\left(n-1\right)/2$ elements contains fitted monotonic distances, dij~$\stackrel{~}{{d}_{ij}}$, for the points in x. The dij~$\stackrel{~}{{d}_{ij}}$ corresponding to distances which are input as missing are set to zero.
If typ = 'S'${\mathbf{typ}}=\text{'S'}$, 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$D$.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, ndim < 1${\mathbf{ndim}}<1$, or ${\mathbf{n}}\le {\mathbf{ndim}}$, or typ ≠ 'T'${\mathbf{typ}}\ne \text{'T'}$ or 'S'$\text{'S'}$, or ldx < n$\mathit{ldx}<{\mathbf{n}}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, all elements of d ≤ 0.0${\mathbf{d}}\le 0.0$.
ifail = 3${\mathbf{ifail}}=3$
The optimization has failed to converge in iter function iterations. Try either increasing the number of iterations using iter or increasing the value of ε$\epsilon$, given by iopt, used to determine convergence. Alternatively try a different starting configuration.
W ifail = 4${\mathbf{ifail}}=4$
The conditions for an acceptable solution have not been met but a lower point could not be found. Try using a larger value of ε$\epsilon$, given by iopt.
ifail = 5${\mathbf{ifail}}=5$
The optimization cannot begin from the initial configuration. Try a different set of points.
ifail = 6${\mathbf{ifail}}=6$
The optimization has failed. This error is only likely if iopt < 0${\mathbf{iopt}}<0$. It corresponds to ${\mathbf{ifail}}={\mathbf{4}}$, 7${\mathbf{7}}$ and 9${\mathbf{9}}$ in nag_opt_uncon_conjgrd_comp (e04dg).

## Accuracy

After a successful optimization the relative accuracy of stress should be approximately ε$\epsilon$, as specified by iopt.

The optimization function nag_opt_uncon_conjgrd_comp (e04dg) used by nag_mv_multidimscal_ordinal (g03fc) has a number of options to control the process. The options for the maximum number of iterations (Iteration Limit) and accuracy (Optimality Tolerance) can be controlled by iter and iopt respectively. The printing option (Print Level) is set to 1$-1$ to give no printing. The other option set is to stop the checking of derivatives (Verify = NO${\mathbf{Verify}}=\mathrm{NO}$) for efficiency. All other options are left at their default values. If however iopt < 0${\mathbf{iopt}}<0$ is used, only the maximum number of iterations is set. All other options can be controlled by the option setting mechanism of nag_opt_uncon_conjgrd_comp (e04dg) with the defaults as given by that function.
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_multidimscal_metric (g03fa) 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_multidimscal_metric (g03fa) to give an initial set of coordinates.

## Example

```function nag_mv_multidimscal_ordinal_example
typ = 'T';
d = [0.099;
0.033;
0.022;
0.183;
0.114;
0.042;
0.148;
0.224;
0.059;
0.068;
0.198;
0.039;
0.053;
0.085;
0.051;
0.462;
0.266;
0.322;
0.435;
0.268;
0.025;
0.628;
0.442;
0.444;
0.406;
0.24;
0.129;
0.014;
0.113;
0.070;
0.046;
0.047;
0.034;
0.002;
0.106;
0.129;
0.173;
0.119;
0.162;
0.331;
0.177;
0.039;
0.089;
0.237;
0.071;
0.434;
0.419;
0.339;
0.505;
0.469;
0.39;
0.315;
0.349;
0.151;
0.43;
0.762;
0.633;
0.781;
0.7;
0.758;
0.625;
0.469;
0.618;
0.44;
0.538;
0.607;
0.53;
0.389;
0.482;
0.579;
0.597;
0.498;
0.374;
0.562;
0.247;
0.383;
0.387;
0.084;
0.586;
0.435;
0.55;
0.53;
0.552;
0.509;
0.369;
0.471;
0.234;
0.346;
0.456;
0.09;
0.038];
x = [0.240788133045093, 0.2336771621940003;
0.1136560325924034, 0.1167860264892129;
0.2393598093421404, 0.07600313166778161;
0.2129341229512031, 0.06047901667594589;
0.249489547604401, -0.0693317659454353;
0.1487285493810621, -0.07783569123014553;
-0.05139397395173806, -0.1623059860926901;
0.01153621118615053, -0.3446314902007094;
-0.003932616383228558, 0.00590873285110863;
0.03856929371547055, -0.008874156731281325;
-0.04211582109685088, -0.05655546538851101;
-0.5158303485449264, 0.02909775244965832;
-0.3180272688082665, 0.1500964500879802;
-0.3237616710329136, 0.04748628317308473];
iter = int64(0);
iopt = int64(0);
[xOut, stress, dfit, ifail] = nag_mv_multidimscal_ordinal(typ, d, x, iter, iopt);
xOut, stress, ifail
```
```

xOut =

0.2060    0.2438
0.1063    0.1418
0.2224    0.0817
0.3032    0.0355
0.2645   -0.0698
0.1554   -0.0435
-0.0070   -0.1612
0.0749   -0.3275
0.0488    0.0289
0.0124   -0.0267
-0.1649   -0.2500
-0.5073    0.1267
-0.3093    0.1590
-0.3498    0.0700

stress =

0.1256

ifail =

0

```
```function g03fc_example
typ = 'T';
d = [0.099;
0.033;
0.022;
0.183;
0.114;
0.042;
0.148;
0.224;
0.059;
0.068;
0.198;
0.039;
0.053;
0.085;
0.051;
0.462;
0.266;
0.322;
0.435;
0.268;
0.025;
0.628;
0.442;
0.444;
0.406;
0.24;
0.129;
0.014;
0.113;
0.070;
0.046;
0.047;
0.034;
0.002;
0.106;
0.129;
0.173;
0.119;
0.162;
0.331;
0.177;
0.039;
0.089;
0.237;
0.071;
0.434;
0.419;
0.339;
0.505;
0.469;
0.39;
0.315;
0.349;
0.151;
0.43;
0.762;
0.633;
0.781;
0.7;
0.758;
0.625;
0.469;
0.618;
0.44;
0.538;
0.607;
0.53;
0.389;
0.482;
0.579;
0.597;
0.498;
0.374;
0.562;
0.247;
0.383;
0.387;
0.084;
0.586;
0.435;
0.55;
0.53;
0.552;
0.509;
0.369;
0.471;
0.234;
0.346;
0.456;
0.09;
0.038];
x = [0.240788133045093, 0.2336771621940003;
0.1136560325924034, 0.1167860264892129;
0.2393598093421404, 0.07600313166778161;
0.2129341229512031, 0.06047901667594589;
0.249489547604401, -0.0693317659454353;
0.1487285493810621, -0.07783569123014553;
-0.05139397395173806, -0.1623059860926901;
0.01153621118615053, -0.3446314902007094;
-0.003932616383228558, 0.00590873285110863;
0.03856929371547055, -0.008874156731281325;
-0.04211582109685088, -0.05655546538851101;
-0.5158303485449264, 0.02909775244965832;
-0.3180272688082665, 0.1500964500879802;
-0.3237616710329136, 0.04748628317308473];
iter = int64(0);
iopt = int64(0);
[xOut, stress, dfit, ifail] = g03fc(typ, d, x, iter, iopt);
xOut, stress, ifail
```
```

xOut =

0.2060    0.2438
0.1063    0.1418
0.2224    0.0817
0.3032    0.0355
0.2645   -0.0698
0.1554   -0.0435
-0.0070   -0.1612
0.0749   -0.3275
0.0488    0.0289
0.0124   -0.0267
-0.1649   -0.2500
-0.5073    0.1267
-0.3093    0.1590
-0.3498    0.0700

stress =

0.1256

ifail =

0

```