NAG Library Routine Document
g03bcf
(rot_procrustes)
1
Purpose
g03bcf computes Procrustes rotations in which an orthogonal rotation is found so that a transformed matrix best matches a target matrix.
2
Specification
Fortran Interface
Subroutine g03bcf ( |
stand,
pscale,
n,
m,
x,
ldx,
y,
ldy,
yhat,
r,
ldr,
alpha,
rss,
res,
wk,
ifail) |
Integer, Intent (In) | :: |
n,
m,
ldx,
ldy,
ldr | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), Intent (Inout) | :: |
x(ldx,m),
y(ldy,m),
yhat(ldy,m),
r(ldr,m) | Real (Kind=nag_wp), Intent (Out) | :: |
alpha,
rss,
res(n),
wk(m*m+7*m) | Character (1), Intent (In) | :: |
stand,
pscale |
|
C Header Interface
#include nagmk26.h
void |
g03bcf_ (
const char *stand,
const char *pscale,
const Integer *n,
const Integer *m,
double x[],
const Integer *ldx,
double y[],
const Integer *ldy,
double yhat[],
double r[],
const Integer *ldr,
double *alpha,
double *rss,
double res[],
double wk[],
Integer *ifail,
const Charlen length_stand,
const Charlen length_pscale) |
|
3
Description
Let and be by matrices. They can be considered as representing sets of points in an -dimensional space. The matrix may be a matrix of loadings from say factor or canonical variate analysis, and the 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 matrix is considered as the target matrix and the 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
and
, i.e., the matrices will have zero column means. Then the rotation of the translated
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
and
are orthogonal matrices and
is a diagonal matrix. The matrix of rotations,
, is computed as:
After rotation, a scaling or dilation factor,
, may be estimated by least squares. Thus, the final set of points that best match
is given by:
Before rotation, both sets of points may be normalized to have unit sums of squares or the
matrix may be normalized to have the same sum of squares as the
matrix. After rotation, the results may be translated to the original
centroid.
The th residual, , is given by the distance between the point given in the th row of and the point given in the th row of . The residual sum of squares is also computed.
4
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
5
Arguments
- 1: – Character(1)Input
-
On entry: indicates if translation/normalization is required.
- There is no translation or normalization.
- There is translation to the origin (i.e., to zero).
- There is translation to origin and then to the centroid after rotation.
- There is unit normalization.
- There is translation and normalization (i.e., there is standardization).
- There is translation and normalization to scale, then translation to the centroid after rotation (i.e., they are matched).
Constraint:
, , , , or .
- 2: – Character(1)Input
-
On entry: indicates if least squares scaling is to be applied after rotation.
- Scaling is applied.
- No scaling is applied.
Constraint:
or .
- 3: – IntegerInput
-
On entry: , the number of points.
Constraint:
.
- 4: – IntegerInput
-
On entry: , the number of dimensions.
Constraint:
.
- 5: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: , the matrix to be rotated.
On exit: if
,
x will be unchanged.
If
,
,
or
,
x will be translated to have zero column means.
If
or
,
x will be scaled to have unit sum of squares.
If
,
x will be scaled to have the same sum of squares as
y.
- 6: – IntegerInput
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g03bcf is called.
Constraint:
.
- 7: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the target matrix, .
On exit: if
,
y will be unchanged.
If
or
,
y will be translated to have zero column means.
If
or
,
y will be scaled to have unit sum of squares.
If
or
,
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.
- 8: – IntegerInput
-
On entry: the first dimension of the arrays
y and
yhat as declared in the (sub)program from which
g03bcf is called.
Constraint:
.
- 9: – Real (Kind=nag_wp) arrayOutput
-
On exit: the fitted matrix, .
- 10: – Real (Kind=nag_wp) arrayOutput
-
On exit: the matrix of rotations,
, see
Section 9.
- 11: – IntegerInput
-
On entry: the first dimension of the array
r as declared in the (sub)program from which
g03bcf is called.
Constraint:
.
- 12: – Real (Kind=nag_wp)Output
-
On exit: if
the scaling factor,
; otherwise
alpha is not set.
-
On exit: the residual sum of squares.
- 14: – Real (Kind=nag_wp) arrayOutput
-
On exit: the residuals,
, for .
- 15: – Real (Kind=nag_wp) arrayWorkspace
-
- 16: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | , , , , or , |
or | or . |
-
On entry, either
x or
y contain only zero-points (possibly after translation) when normalization is to be applied.
-
The 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.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
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.
8
Parallelism and Performance
g03bcf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
Note that if the matrix
is not of full rank, then the matrix of rotations,
, may not be unique even if there is a unique solution in terms of the rotated matrix,
. The matrix
may also include reflections as well as pure rotations, see
Krzanowski (1990).
If the column dimensions of the and matrices are not equal, the smaller of the two should be supplemented by columns of zeros. Adding a column of zeros to both and will have the effect of allowing reflections as well as rotations.
10
Example
Three points representing the vertices of a triangle in two dimensions are input. The points are translated and rotated to match the triangle given by , , and scaling is applied after rotation. The target matrix and fitted matrix are printed along with additional information.
10.1
Program Text
Program Text (g03bcfe.f90)
10.2
Program Data
Program Data (g03bcfe.d)
10.3
Program Results
Program Results (g03bcfe.r)