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_rot_procrustes (g03bc)

## Purpose

nag_mv_rot_procrustes (g03bc) computes Procrustes rotations in which an orthogonal rotation is found so that a transformed matrix best matches a target matrix.

## Syntax

[x, y, yhat, r, alpha, rss, res, ifail] = g03bc(stand, pscale, x, y, 'n', n, 'm', m)
[x, y, yhat, r, alpha, rss, res, ifail] = nag_mv_rot_procrustes(stand, pscale, x, y, 'n', n, 'm', m)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: n has been made optional
.

## Description

Let X$X$ and Y$Y$ be n$n$ by m$m$ matrices. They can be considered as representing sets of n$n$ points in an m$m$-dimensional space. The X$X$ matrix may be a matrix of loadings from say factor or canonical variate analysis, and the Y$Y$ matrix may be a postulated pattern matrix or the loadings from a different sample. The problem is to relate the two sets of points without disturbing the relationships between the points in each set. This can be achieved by translating, rotating and scaling the sets of points. The Y$Y$ matrix is considered as the target matrix and the X$X$ matrix is rotated to match that matrix.
First the two sets of points are translated so that their centroids are at the origin to give Xc${X}_{c}$ and Yc${Y}_{c}$, i.e., the matrices will have zero column means. Then the rotation of the translated Xc${X}_{c}$ matrix which minimizes the sum of squared distances between corresponding points in the two sets is found. This is computed from the singular value decomposition of the matrix:
 XcTYc = UDVT, $XcTYc=UDVT,$
where U$U$ and V$V$ are orthogonal matrices and D$D$ is a diagonal matrix. The matrix of rotations, R$R$, is computed as:
 R = UVT. $R=UVT.$
After rotation, a scaling or dilation factor, α$\alpha$, may be estimated by least squares. Thus, the final set of points that best match Yc${Y}_{c}$ is given by:
 Ŷc = αXcR. $Y^c=αXcR.$
Before rotation, both sets of points may be normalized to have unit sums of squares or the X$X$ matrix may be normalized to have the same sum of squares as the Y$Y$ matrix. After rotation, the results may be translated to the original Y$Y$ centroid.
The i$i$th residual, ri${r}_{i}$, is given by the distance between the point given in the i$i$th row of Y$Y$ and the point given in the i$i$th row of $\stackrel{^}{Y}$. The residual sum of squares is also computed.

## References

Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
Lawley D N and Maxwell A E (1971) Factor Analysis as a Statistical Method (2nd Edition) Butterworths

## Parameters

### Compulsory Input Parameters

1:     stand – string (length ≥ 1)
Indicates if translation/normalization is required.
stand = 'N'${\mathbf{stand}}=\text{'N'}$
There is no translation or normalization.
stand = 'Z'${\mathbf{stand}}=\text{'Z'}$
There is translation to the origin (i.e., to zero).
stand = 'C'${\mathbf{stand}}=\text{'C'}$
There is translation to origin and then to the Y$Y$ centroid after rotation.
stand = 'U'${\mathbf{stand}}=\text{'U'}$
There is unit normalization.
stand = 'S'${\mathbf{stand}}=\text{'S'}$
There is translation and normalization (i.e., there is standardization).
stand = 'M'${\mathbf{stand}}=\text{'M'}$
There is translation and normalization to Y$Y$ scale, then translation to the Y$Y$ centroid after rotation (i.e., they are matched).
Constraint: stand = 'N'${\mathbf{stand}}=\text{'N'}$, 'Z'$\text{'Z'}$, 'C'$\text{'C'}$, 'U'$\text{'U'}$, 'S'$\text{'S'}$ or 'M'$\text{'M'}$.
2:     pscale – string (length ≥ 1)
Indicates if least squares scaling is to be applied after rotation.
pscale = 'S'${\mathbf{pscale}}=\text{'S'}$
Scaling is applied.
pscale = 'U'${\mathbf{pscale}}=\text{'U'}$
No scaling is applied.
Constraint: pscale = 'S'${\mathbf{pscale}}=\text{'S'}$ or 'U'$\text{'U'}$.
3:     x(ldx,m) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxn$\mathit{ldx}\ge {\mathbf{n}}$.
X$X$, the matrix to be rotated.
4:     y(ldy,m) – double array
ldy, the first dimension of the array, must satisfy the constraint ldyn$\mathit{ldy}\ge {\mathbf{n}}$.
The target matrix, y${\mathbf{y}}$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
n$n$, the number of points.
Constraint: nm${\mathbf{n}}\ge {\mathbf{m}}$.
2:     m – int64int32nag_int scalar
Default: The second dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
m$m$, the number of dimensions.
Constraint: m1${\mathbf{m}}\ge 1$.

ldx ldy ldr wk

### Output Parameters

1:     x(ldx,m) – double array
ldxn$\mathit{ldx}\ge {\mathbf{n}}$.
If stand = 'N'${\mathbf{stand}}=\text{'N'}$, x will be unchanged.
If stand = 'Z'${\mathbf{stand}}=\text{'Z'}$, 'C'$\text{'C'}$, 'S'$\text{'S'}$ or 'M'$\text{'M'}$, x will be translated to have zero column means.
If stand = 'U'${\mathbf{stand}}=\text{'U'}$ or 'S'$\text{'S'}$, x will be scaled to have unit sum of squares.
If stand = 'M'${\mathbf{stand}}=\text{'M'}$, x will be scaled to have the same sum of squares as y.
2:     y(ldy,m) – double array
ldyn$\mathit{ldy}\ge {\mathbf{n}}$.
If stand = 'N'${\mathbf{stand}}=\text{'N'}$, y will be unchanged.
If stand = 'Z'${\mathbf{stand}}=\text{'Z'}$ or 'S'$\text{'S'}$, y will be translated to have zero column means.
If stand = 'U'${\mathbf{stand}}=\text{'U'}$ or 'S'$\text{'S'}$, y will be scaled to have unit sum of squares.
If stand = 'C'${\mathbf{stand}}=\text{'C'}$ or 'M'$\text{'M'}$, y will be translated and then after rotation translated back. The output y should be the same as the input y except for rounding errors.
3:     yhat(ldy,m) – double array
ldyn$\mathit{ldy}\ge {\mathbf{n}}$.
The fitted matrix, $\stackrel{^}{Y}$.
4:     r(ldr,m) – double array
ldrm$\mathit{ldr}\ge {\mathbf{m}}$.
The matrix of rotations, R$R$, see Section [Further Comments].
5:     alpha – double scalar
If pscale = 'S'${\mathbf{pscale}}=\text{'S'}$ the scaling factor, α$\alpha$; otherwise alpha is not set.
The residual sum of squares.
7:     res(n) – double array
The residuals, ri${r}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
8:     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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n < m${\mathbf{n}}<{\mathbf{m}}$, or m < 1${\mathbf{m}}<1$, or ldx < n$\mathit{ldx}<{\mathbf{n}}$, or ldy < n$\mathit{ldy}<{\mathbf{n}}$, or ldr < m$\mathit{ldr}<{\mathbf{m}}$, or stand ≠ 'N'${\mathbf{stand}}\ne \text{'N'}$, 'Z'$\text{'Z'}$, 'C'$\text{'C'}$, 'U'$\text{'U'}$, 'S'$\text{'S'}$ or 'M'$\text{'M'}$, or pscale ≠ 'S'${\mathbf{pscale}}\ne \text{'S'}$ or 'U'$\text{'U'}$.
ifail = 2${\mathbf{ifail}}=2$
On entry, either x or y contain only zero-points (possibly after translation) when normalization is to be applied.
ifail = 3${\mathbf{ifail}}=3$
The $\stackrel{^}{Y}$ matrix contains only zero-points when least squares scaling is applied.
ifail = 4${\mathbf{ifail}}=4$
The singular value decomposition has failed to converge. This is an unlikely error exit.

## Accuracy

The accuracy of the calculation of the rotation matrix largely depends upon the singular value decomposition. See the F08 Chapter Introduction for further details.

Note that if the matrix XcTY${X}_{c}^{\mathrm{T}}Y$ is not of full rank, then the matrix of rotations, R$R$, may not be unique even if there is a unique solution in terms of the rotated matrix, c${\stackrel{^}{Y}}_{c}$. The matrix R$R$ may also include reflections as well as pure rotations, see Krzanowski (1990).
If the column dimensions of the X$X$ and Y$Y$ matrices are not equal, the smaller of the two should be supplemented by columns of zeros. Adding a column of zeros to both X$X$ and Y$Y$ will have the effect of allowing reflections as well as rotations.

## Example

```function nag_mv_rot_procrustes_example
stand = 'c';
pscale = 's';
x = [0.63, 0.58;
1.36, 0.39;
1.01, 1.76];
y = [0, 0;
1, 0;
0, 2];
[xOut, yOut, yhat, r, alpha, rss, res, ifail] = nag_mv_rot_procrustes(stand, pscale, x, y)
```
```

xOut =

-0.3700   -0.3300
0.3600   -0.5200
0.0100    0.8500

yOut =

0     0
1     0
0     2

yhat =

-0.0934    0.0239
1.0805    0.0259
0.0130    1.9502

r =

0.9673    0.2536
-0.2536    0.9673

alpha =

1.5563

0.0191

res =

0.0964
0.0846
0.0514

ifail =

0

```
```function g03bc_example
stand = 'c';
pscale = 's';
x = [0.63, 0.58;
1.36, 0.39;
1.01, 1.76];
y = [0, 0;
1, 0;
0, 2];
[xOut, yOut, yhat, r, alpha, rss, res, ifail] = g03bc(stand, pscale, x, y)
```
```

xOut =

-0.3700   -0.3300
0.3600   -0.5200
0.0100    0.8500

yOut =

0     0
1     0
0     2

yhat =

-0.0934    0.0239
1.0805    0.0259
0.0130    1.9502

r =

0.9673    0.2536
-0.2536    0.9673

alpha =

1.5563

0.0191

res =

0.0964
0.0846
0.0514

ifail =

0

```