hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_mv_canon_corr (g03ad)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_mv_canon_corr (g03ad) performs canonical correlation analysis upon input data matrices.

Syntax

[e, ncv, cvx, cvy, ifail] = g03ad(z, isz, nx, ny, mcv, tol, 'n', n, 'm', m, 'wt', wt)
[e, ncv, cvx, cvy, ifail] = nag_mv_canon_corr(z, isz, nx, ny, mcv, tol, 'n', n, 'm', m, 'wt', wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 24: weight was removed from the interface; wt was made optional
At Mark 22: n was made optional

Description

Let there be two sets of variables, x and y. For a sample of n observations on nx variables in a data matrix X and ny variables in a data matrix Y, 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
Sxx Sxy Syx Syy  
and let
Σ=Syy -1SyxSxx -1Sxy  
then the canonical correlations can be calculated from the eigenvalues of the matrix Σ. However, nag_mv_canon_corr (g03ad) calculates the canonical correlations by means of a singular value decomposition (SVD) of a matrix V. If the rank of the data matrix X is kx and the rank of the data matrix Y is ky, and both X and Y have had variable (column) means subtracted then the kx by ky matrix V is given by:
V=QxTQy,  
where Qx is the first kx columns of the orthogonal matrix Q either from the QR decomposition of X if X is of full column rank, i.e., kx=nx:
X=QxRx  
or from the SVD of X if kx<nx:
X=QxDxPxT.  
Similarly Qy is the first ky columns of the orthogonal matrix Q either from the QR decomposition of Y if Y is of full column rank, i.e., ky=ny:
Y=QyRy  
or from the SVD of Y if ky<ny:
Y=QyDyPyT.  
Let the SVD of V be:
V=UxΔUyT  
then the nonzero elements of the diagonal matrix Δ, δi, for i=1,2,,l, are the l canonical correlations associated with the l canonical variates, where l = minkx,ky .
The eigenvalues, λi2, of the matrix Σ are given by:
λi2 = δi2 .  
The value of πi=λi2/λi2 gives the proportion of variation explained by the ith canonical variate. The values of the πi'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 i the χ2 statistic:
n - 12 kx + ky + 3 j=i+1 l log 1 - δj2  
can be used. This is asymptotically distributed as a χ2-distribution with kx-iky-i degrees of freedom. If the test for i=kmin is not significant, then the remaining tests for i>kmin should be ignored.
The loadings for the canonical variates are calculated from the matrices Ux and Uy respectively. These matrices are scaled so that the canonical variates have unit variance.

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

Parameters

Compulsory Input Parameters

1:     zldzm – double array
ldz, the first dimension of the array, must satisfy the constraint ldzn.
zij must contain the ith observation for the jth variable, for i=1,2,,n and j=1,2,,m.
Both x and y variables are to be included in z, the indicator array, isz, being used to assign the variables in z to the x or y sets as appropriate.
2:     iszm int64int32nag_int array
iszj indicates whether or not the jth variable is included in the analysis and to which set of variables it belongs.
iszj>0
The variable contained in the jth column of z is included as an x variable in the analysis.
iszj<0
The variable contained in the jth column of z is included as a y variable in the analysis.
iszj=0
The variable contained in the jth column of z is not included in the analysis.
Constraint: only nx elements of isz can be >0 and only ny elements of isz can be <0.
3:     nx int64int32nag_int scalar
The number of x variables in the analysis, nx.
Constraint: nx1.
4:     ny int64int32nag_int scalar
The number of y variables in the analysis, ny.
Constraint: ny1.
5:     mcv int64int32nag_int scalar
An upper limit to the number of canonical variates.
Constraint: mcvminnx,ny.
6:     tol – double scalar
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: tol0.0.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array wt and the first dimension of the array z. (An error is raised if these dimensions are not equal.)
n, the number of observations.
Constraint: n>nx+ny.
2:     m int64int32nag_int scalar
Default: the dimension of the array isz and the second dimension of the array z. (An error is raised if these dimensions are not equal.)
m, the total number of variables.
Constraint: mnx+ny.
3:     wt: – double array
The dimension of the array wt must be at least n if weight='W', and at least 1 otherwise
If weight='W', the first n elements of wt must contain the weights to be used in the analysis.
If wti=0.0, the ith observation is not included in the analysis. The effective number of observations is the sum of weights.
If weight='U', wt is not referenced and the effective number of observations is n.
Constraints:
  • wti0.0, for i=1,2,,n;
  • the sum of weightsnx+ny+1.

Output Parameters

1:     elde6 – double array
The statistics of the canonical variate analysis.
ei1
The canonical correlations, δi, for i=1,2,,l.
ei2
The eigenvalues of Σ, λi2, for i=1,2,,l.
ei3
The proportion of variation explained by the ith canonical variate, for i=1,2,,l.
ei4
The χ2 statistic for the ith canonical variate, for i=1,2,,l.
ei5
The degrees of freedom for χ2 statistic for the ith canonical variate, for i=1,2,,l.
ei6
The significance level for the χ2 statistic for the ith canonical variate, for i=1,2,,l.
2:     ncv int64int32nag_int scalar
The number of canonical correlations, l. This will be the minimum of the rank of X and the rank of Y.
3:     cvxldcvxmcv – double array
The canonical variate loadings for the x variables. cvxij contains the loading coefficient for the ith x variable on the jth canonical variate.
4:     cvyldcvymcv – double array
The canonical variate loadings for the y variables. cvyij contains the loading coefficient for the ith y variable on the jth canonical variate.
5:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

   ifail=1
On entry,nx<1,
orny<1,
orm<nx+ny,
ornnx+ny,
or mcv < minnx,ny ,
orldz<n,
orldcvx<nx,
orldcvy<ny,
or lde < minnx,ny ,
ornxny and
iwk<n×nx+nx+ny+max5×nx-1+nx×nx,n×ny,
ornx<ny and
iwk<n×ny+nx+ny+max5×ny-1+ny×ny,n×nx,
orweight'U' or 'W',
ortol<0.0.
   ifail=2
On entry,a weight='W' and value of wt<0.0.
   ifail=3
On entry,the number of x variables to be included in the analysis as indicated by isz is not equal to nx.
orthe number of y variables to be included in the analysis as indicated by isz is not equal to ny.
   ifail=4
On entry,the effective number of observations is less than nx+ny+1.
   ifail=5
A singular value decomposition has failed to converge. See nag_eigen_real_triang_svd (f02wu). This is an unlikely error exit.
W  ifail=6
A canonical correlation is equal to 1. This will happen if the x and y variables are perfectly correlated.
W  ifail=7
On entry, the rank of the X matrix or the rank of the Y matrix is 0. This will happen if all the x or y variables are constants.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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, nag_mv_canon_corr (g03ad) should be less affected by ill-conditioned problems.

Further Comments

None.

Example

This example has nine observations and two variables in each set of the four variables read in, the second and third are x variables while the first and last are y variables. Canonical variate analysis is performed and the results printed.
function g03ad_example


fprintf('g03ad example results\n\n');

z   = [80, 58.4, 14.0, 21;
       75, 59.2, 15.0, 27;
       78, 60.3, 15.0, 27;
       75, 57.4, 13.0, 22;
       79, 59.5, 14.0, 26;
       78, 58.1, 14.5, 26;
       75, 58.0, 12.5, 23;
       64, 55.5, 11.0, 22;
       80, 59.2, 12.5, 22];
isz = [int64(-1);1;1;-1];
nx  = int64(2);
ny  = nx;
mcv = nx;
tol = 1e-06;

[e, ncv, cvx, cvy, ifail] = ...
  g03ad( ...
	 z, isz, nx, ny, mcv, tol);

fprintf('Rank of x = %d, Rank of y = %d\n\n', nx, ny);
fprintf('Canonical    Eigenvalues Percentage     Chisq      DF     Sig\n');
fprintf('correlations              variation\n');
fprintf('%11.4f%12.4f%12.4f%10.4f%8.1f%8.4f\n',e');
fprintf('\n');

mtitle = 'Canonical Coefficients for x';
matrix = 'General';
diag   = ' ';
[ifail] = x04ca( ...
                 matrix, diag, cvx, mtitle);

fprintf('\n');
mtitle = 'Canonical Coefficients for y';
[ifail] = x04ca( ...
                 matrix, diag, cvy, mtitle);


g03ad example results

Rank of x = 2, Rank of y = 2

Canonical    Eigenvalues Percentage     Chisq      DF     Sig
correlations              variation
     0.9570      0.9159      0.8746   14.3914     4.0  0.0061
     0.3624      0.1313      0.1254    0.7744     1.0  0.3789

 Canonical Coefficients for x
             1          2
 1     -0.4261     1.0337
 2     -0.3444    -1.1136

 Canonical Coefficients for y
          1       2
 1  -0.1415  0.1504
 2  -0.2384 -0.3424

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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