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

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.

Mark 22: n has been made optional

.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 X_{c}${X}_{c}$ and Y_{c}${Y}_{c}$, i.e., the matrices will have zero column means. Then the rotation of the translated X_{c}${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:

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:

After rotation, a scaling or dilation factor, α$\alpha $, may be estimated by least squares. Thus, the final set of points that best match Y_{c}${Y}_{c}$ is given by:

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.

X _{c}^{T}Y_{c} = UDV^{T},
$${X}_{c}^{\mathrm{T}}{Y}_{c}=UD{V}^{\mathrm{T}}\text{,}$$ |

R = UV ^{T}.
$$R=U{V}^{\mathrm{T}}\text{.}$$ |

Ŷ _{c} = αX_{c}R.
$${\hat{Y}}_{c}=\alpha {X}_{c}R\text{.}$$ |

The i$i$th residual, r_{i}${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 Ŷ$\hat{Y}$. The residual sum of squares is also computed.

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

- 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.
- 3: x(ldx,m) – double array
- ldx, the first dimension of the array, must satisfy the constraint ldx ≥ n$\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 ldy ≥ n$\mathit{ldy}\ge {\mathbf{n}}$.The target matrix, y${\mathbf{y}}$.

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

- ldx ldy ldr wk

- 1: x(ldx,m) – double array
- ldx ≥ n$\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.
- 2: y(ldy,m) – double array
- ldy ≥ n$\mathit{ldy}\ge {\mathbf{n}}$.
- 3: yhat(ldy,m) – double array
- ldy ≥ n$\mathit{ldy}\ge {\mathbf{n}}$.The fitted matrix, Ŷ$\hat{Y}$.
- 4: r(ldr,m) – double array
- ldr ≥ m$\mathit{ldr}\ge {\mathbf{m}}$.
- 5: alpha – double scalar
- 6: rss – double scalar
- The residual sum of squares.
- 7: res(n) – double array
- The residuals, r
_{i}${r}_{\mathit{i}}$, for i = 1,2, … ,n$\mathit{i}=1,2,\dots ,n$. - 8: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Errors or warnings detected by the function:

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'}$.

- The Ŷ$\hat{Y}$ matrix contains only zero-points when least squares scaling is applied.

- The singular value decomposition has failed to converge. This is an unlikely error exit.

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 X_{c}^{T}Y${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}${\hat{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.

Open in the MATLAB editor: nag_mv_rot_procrustes_example

function nag_mv_rot_procrustes_examplestand = '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 rss = 0.0191 res = 0.0964 0.0846 0.0514 ifail = 0

Open in the MATLAB editor: g03bc_example

function g03bc_examplestand = '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 rss = 0.0191 res = 0.0964 0.0846 0.0514 ifail = 0

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013