NAG Library Routine Document
G03ADF
1 Purpose
G03ADF performs canonical correlation analysis upon input data matrices.
2 Specification
SUBROUTINE G03ADF ( |
WEIGHT, N, M, Z, LDZ, ISZ, NX, NY, WT, E, LDE, NCV, CVX, LDCVX, MCV, CVY, LDCVY, TOL, WK, IWK, IFAIL) |
INTEGER |
N, M, LDZ, ISZ(M), NX, NY, LDE, NCV, LDCVX, MCV, LDCVY, IWK, IFAIL |
REAL (KIND=nag_wp) |
Z(LDZ,M), WT(*), E(LDE,6), CVX(LDCVX,MCV), CVY(LDCVY,MCV), TOL, WK(IWK) |
CHARACTER(1) |
WEIGHT |
|
3 Description
Let there be two sets of variables, and . For a sample of observations on variables in a data matrix and variables in a data matrix , canonical correlation analysis seeks to find a small number of linear combinations of each set of variables in order to explain or summarise the relationships between them. The variables thus formed are known as canonical variates.
Let the variance-covariance matrix of the two datasets be
and let
then the canonical correlations can be calculated from the eigenvalues of the matrix
. However, G03ADF calculates the canonical correlations by means of a singular value decomposition (SVD) of a matrix
. If the rank of the data matrix
is
and the rank of the data matrix
is
, and both
and
have had variable (column) means subtracted then the
by
matrix
is given by:
where
is the first
columns of the orthogonal matrix
either from the
decomposition of
if
is of full column rank, i.e.,
:
or from the SVD of
if
:
Similarly
is the first
columns of the orthogonal matrix
either from the
decomposition of
if
is of full column rank, i.e.,
:
or from the SVD of
if
:
Let the SVD of
be:
then the nonzero elements of the diagonal matrix
,
, for
, are the
canonical correlations associated with the
canonical variates, where
.
The eigenvalues,
, of the matrix
are given by:
The value of
gives the proportion of variation explained by the
th canonical variate. The values of the
's give an indication as to how many canonical variates are needed to adequately describe the data, i.e., the dimensionality of the problem.
To test for a significant dimensionality greater than
the
statistic:
can be used. This is asymptotically distributed as a
-distribution with
degrees of freedom. If the test for
is not significant, then the remaining tests for
should be ignored.
The loadings for the canonical variates are calculated from the matrices and respectively. These matrices are scaled so that the canonical variates have unit variance.
4 References
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
Kendall M G and Stuart A (1976) The Advanced Theory of Statistics (Volume 3) (3rd Edition) Griffin
Morrison D F (1967) Multivariate Statistical Methods McGraw–Hill
5 Parameters
- 1: – CHARACTER(1)Input
-
On entry: indicates if weights are to be used.
- No weights are used.
- Weights are used and must be supplied in WT.
Constraint:
or .
- 2: – INTEGERInput
-
On entry: , the number of observations.
Constraint:
.
- 3: – INTEGERInput
-
On entry: , the total number of variables.
Constraint:
.
- 4: – REAL (KIND=nag_wp) arrayInput
-
On entry:
must contain the
th observation for the
th variable, for
and
.
Both
and
variables are to be included in
Z, the indicator array,
ISZ, being used to assign the variables in
Z to the
or
sets as appropriate.
- 5: – INTEGERInput
-
On entry: the first dimension of the array
Z as declared in the (sub)program from which G03ADF is called.
Constraint:
.
- 6: – INTEGER arrayInput
-
On entry:
indicates whether or not the
th variable is included in the analysis and to which set of variables it belongs.
- The variable contained in the th column of Z is included as an variable in the analysis.
- The variable contained in the th column of Z is included as a variable in the analysis.
- The variable contained in the th column of Z is not included in the analysis.
Constraint:
only
NX elements of
ISZ can be
and only
NY elements of
ISZ can be
.
- 7: – INTEGERInput
-
On entry: the number of variables in the analysis, .
Constraint:
.
- 8: – INTEGERInput
-
On entry: the number of variables in the analysis, .
Constraint:
.
- 9: – REAL (KIND=nag_wp) arrayInput
-
Note: the dimension of the array
WT
must be at least
if
, and at least
otherwise.
On entry: if
, the first
elements of
WT must contain the weights to be used in the analysis.
If , the th observation is not included in the analysis. The effective number of observations is the sum of weights.
If
,
WT is not referenced and the effective number of observations is
.
Constraints:
- , for ;
- the .
- 10: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the statistics of the canonical variate analysis.
- The canonical correlations,
, for .
- The eigenvalues of ,
, for .
- The proportion of variation explained by the
th canonical variate, for .
- The statistic for the
th canonical variate, for .
- The degrees of freedom for statistic for the
th canonical variate, for .
- The significance level for the statistic for the
th canonical variate, for .
- 11: – INTEGERInput
-
On entry: the first dimension of the array
E as declared in the (sub)program from which G03ADF is called.
Constraint:
.
- 12: – INTEGEROutput
-
On exit: the number of canonical correlations, . This will be the minimum of the rank of and the rank of .
- 13: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the canonical variate loadings for the variables. contains the loading coefficient for the th variable on the th canonical variate.
- 14: – INTEGERInput
-
On entry: the first dimension of the array
CVX as declared in the (sub)program from which G03ADF is called.
Constraint:
.
- 15: – INTEGERInput
-
On entry: an upper limit to the number of canonical variates.
Constraint:
.
- 16: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the canonical variate loadings for the variables. contains the loading coefficient for the th variable on the th canonical variate.
- 17: – INTEGERInput
-
On entry: the first dimension of the array
CVY as declared in the (sub)program from which G03ADF is called.
Constraint:
.
- 18: – REAL (KIND=nag_wp)Input
-
On entry: the value of
TOL is used to decide if the variables are of full rank and, if not, what is the rank of the variables. The smaller the value of
TOL the stricter the criterion for selecting the singular value decomposition. If a non-negative value of
TOL less than
machine precision is entered, the square root of
machine precision is used instead.
Constraint:
.
- 19: – REAL (KIND=nag_wp) arrayWorkspace
- 20: – INTEGERInput
-
On entry: the dimension of the array
WK as declared in the (sub)program from which G03ADF is called.
Constraints:
- if , ;
- if , .
- 21: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction 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 parameter, 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 | , |
or | and , |
or | and , |
or | or , |
or | . |
-
On entry, | a and value of . |
-
On entry, | the number of variables to be included in the analysis as indicated by ISZ is not equal to NX. |
or | the number of variables to be included in the analysis as indicated by ISZ is not equal to NY. |
-
On entry, | the effective number of observations is less than . |
-
A singular value decomposition has failed to converge. See
F02WUF. This is an unlikely error exit.
-
A canonical correlation is equal to . This will happen if the and variables are perfectly correlated.
-
On entry, the rank of the matrix or the rank of the matrix is . This will happen if all the or variables are constants.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
As the computation involves the use of orthogonal matrices and a singular value decomposition rather than the traditional computing of a sum of squares matrix and the use of an eigenvalue decomposition, G03ADF should be less affected by ill-conditioned problems.
8 Parallelism and Performance
G03ADF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G03ADF 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.
None.
10 Example
This example has nine observations and two variables in each set of the four variables read in, the second and third are variables while the first and last are variables. Canonical variate analysis is performed and the results printed.
10.1 Program Text
Program Text (g03adfe.f90)
10.2 Program Data
Program Data (g03adfe.d)
10.3 Program Results
Program Results (g03adfe.r)