NAG Library Routine Document
g03adf
(canon_corr)
1
Purpose
g03adf performs canonical correlation analysis upon input data matrices.
2
Specification
Fortran Interface
Subroutine g03adf ( |
weight,
n,
m,
z,
ldz,
isz,
nx,
ny,
wt,
e,
lde,
ncv,
cvx,
ldcvx,
mcv,
cvy,
ldcvy,
tol,
wk,
iwk,
ifail) |
Integer, Intent (In) | :: |
n,
m,
ldz,
isz(m),
nx,
ny,
lde,
ldcvx,
mcv,
ldcvy,
iwk | Integer, Intent (Inout) | :: |
ifail | Integer, Intent (Out) | :: |
ncv | Real (Kind=nag_wp), Intent (In) | :: |
z(ldz,m),
wt(*),
tol | Real (Kind=nag_wp), Intent (Inout) | :: |
e(lde,6),
cvx(ldcvx,mcv),
cvy(ldcvy,mcv) | Real (Kind=nag_wp), Intent (Out) | :: |
wk(iwk) | Character (1), Intent (In) | :: |
weight |
|
C Header Interface
#include nagmk26.h
void |
g03adf_ (
const char *weight,
const Integer *n,
const Integer *m,
const double z[],
const Integer *ldz,
const Integer isz[],
const Integer *nx,
const Integer *ny,
const double wt[],
double e[],
const Integer *lde,
Integer *ncv,
double cvx[],
const Integer *ldcvx,
const Integer *mcv,
double cvy[],
const Integer *ldcvy,
const double *tol,
double wk[],
const Integer *iwk,
Integer *ifail,
const Charlen length_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
Arguments
- 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 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 | , |
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.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
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)