The routine may be called by the names g03adf or nagf_mv_canon_corr.
3Description
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 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.
4References
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
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 , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or 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).
6Error 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,
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: or .
On entry, and .
Constraint: .
On entry, , expected . Constraint: must be consistent with isz.
On entry, , expected .
Constraint: must be consistent with isz.
On entry, the effective number of observations is less than .
The singular value decomposition has failed to converge. 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 is .
On entry, the rank of the matrix is .
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
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.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
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.
9Further Comments
None.
10Example
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.