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)

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:
Mark 22: n has been made optional
Mark 24: drop weight, wt optional
.

Description

Let there be two sets of variables, x x  and y y . For a sample of n n  observations on nx nx  variables in a data matrix X X  and ny ny  variables in a data matrix Y 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
(SxxSxy)
Syx Syy
( Sxx Sxy Syx Syy )
and let
Σ = Syy1SyxSxx1Sxy
Σ=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 V . If the rank of the data matrix X X  is kx kx  and the rank of the data matrix Y Y  is ky ky , and both X X  and Y Y  have had variable (column) means subtracted then the kx kx  by ky ky  matrix V V  is given by:
V = QxTQy,
V=QxTQy,
where Qx Qx  is the first kx kx  columns of the orthogonal matrix Q Q  either from the QR QR  decomposition of X X  if X X  is of full column rank, i.e., kx = nx kx=nx :
X = QxRx
X=QxRx
or from the SVD of X X  if kx < nx kx<nx :
X = QxDxPxT.
X=QxDxPxT.
Similarly Qy Qy  is the first ky ky  columns of the orthogonal matrix Q Q  either from the QR QR  decomposition of Y Y  if Y Y  is of full column rank, i.e., ky = ny ky=ny :
Y = QyRy
Y=QyRy
or from the SVD of Y Y  if ky < ny ky<ny :
Y = QyDyPyT.
Y=QyDyPyT.
Let the SVD of V V  be:
V = UxΔUyT
V=UxΔUyT
then the nonzero elements of the diagonal matrix Δ Δ , δi δi , for i = 1,2,,l i=1,2,,l , are the l l  canonical correlations associated with the l l  canonical variates, where l = min (kx,ky) l = min (kx,ky) .
The eigenvalues, λi2 λi2 , of the matrix Σ Σ  are given by:
λi2 = δi2 .
λi2 = δi2 .
The value of πi = λi2 / λi2 πi=λi2/λi2  gives the proportion of variation explained by the i i th canonical variate. The values of the πi π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 i  the χ2 χ2  statistic:
l
(n(1/2)(kx + ky + 3))log(1δj2)
j = i + 1
(n-12 (kx+ky+3) ) j=i+1 l log (1-δj2)
can be used. This is asymptotically distributed as a χ2 χ2 -distribution with (kxi)(kyi) (kx-i) (ky-i)  degrees of freedom. If the test for i = kmin i=kmin  is not significant, then the remaining tests for i > kmin i>kmin  should be ignored.
The loadings for the canonical variates are calculated from the matrices Ux Ux  and Uy 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:     z(ldz,m) – double array
ldz, the first dimension of the array, must satisfy the constraint ldzn ldzn .
z(i,j) z (i,j)  must contain the i i th observation for the j j th variable, for i = 1,2,,n i=1,2,,n  and j = 1,2,,m j=1,2,,m .
Both x x  and y y  variables are to be included in z, the indicator array, isz, being used to assign the variables in z to the x x  or y y  sets as appropriate.
2:     isz(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint mnx + ny mnx+ny .
isz(j) isz (j)  indicates whether or not the j j th variable is included in the analysis and to which set of variables it belongs.
isz(j) > 0 isz (j) >0
The variable contained in the j j th column of z is included as an x x  variable in the analysis.
isz(j) < 0 isz (j) <0
The variable contained in the j j th column of z is included as a y y  variable in the analysis.
isz(j) = 0 isz (j) =0
The variable contained in the j j th column of z is not included in the analysis.
Constraint: only nx elements of isz can be > 0 >0  and only ny elements of isz can be < 0 <0 .
3:     nx – int64int32nag_int scalar
The number of x x  variables in the analysis, nx nx .
Constraint: nx1 nx1 .
4:     ny – int64int32nag_int scalar
The number of y y  variables in the analysis, ny ny .
Constraint: ny1 ny1 .
5:     mcv – int64int32nag_int scalar
An upper limit to the number of canonical variates.
Constraint: mcvmin (nx,ny) mcvmin (nx,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 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 n , the number of observations.
Constraint: n > nx + ny 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 m , the total number of variables.
Constraint: mnx + ny mnx+ny .
3:     wt( : : ) – double array
Note: the dimension of the array wt must be at least n n  if weight = 'W' weight='W' , and at least 1 1  otherwise.
If weight = 'W' weight='W' , the first n n  elements of wt must contain the weights to be used in the analysis.
If wt(i) = 0.0 wt (i) =0.0 , the i i th observation is not included in the analysis. The effective number of observations is the sum of weights.
If weight = 'U' weight='U' , wt is not referenced and the effective number of observations is n n .
Constraints:
  • wt(i)0.0 wt (i) 0.0 , for i = 1,2,,n i=1,2,,n ;
  • the sum of weightsnx + ny + 1 sum of weightsnx+ny+1 .

Input Parameters Omitted from the MATLAB Interface

weight ldz lde ldcvx ldcvy wk iwk

Output Parameters

1:     e(lde,6 6 ) – double array
ldemin (nx,ny) ldemin (nx,ny) .
The statistics of the canonical variate analysis.
e(i,1) e (i,1)
The canonical correlations, δi δi , for i = 1,2,,l i=1,2,,l .
e(i,2) e (i,2)
The eigenvalues of Σ Σ , λi2 λi2 , for i = 1,2,,l i=1,2,,l .
e(i,3) e (i,3)
The proportion of variation explained by the i i th canonical variate, for i = 1,2,,l i=1,2,,l .
e(i,4) e (i,4)
The χ2 χ2 statistic for the i i th canonical variate, for i = 1,2,,l i=1,2,,l .
e(i,5) e (i,5)
The degrees of freedom for χ2 χ2 statistic for the i i th canonical variate, for i = 1,2,,l i=1,2,,l .
e(i,6) e (i,6)
The significance level for the χ2 χ2 statistic for the i i th canonical variate, for i = 1,2,,l i=1,2,,l .
2:     ncv – int64int32nag_int scalar
The number of canonical correlations, l l . This will be the minimum of the rank of X X and the rank of Y Y .
3:     cvx(ldcvx,mcv) – double array
ldcvxnx ldcvxnx .
The canonical variate loadings for the x x variables. cvx(i,j) cvx (i,j) contains the loading coefficient for the i i th x x variable on the j j th canonical variate.
4:     cvy(ldcvy,mcv) – double array
ldcvyny ldcvyny .
The canonical variate loadings for the y y variables. cvy(i,j) cvy (i,j) contains the loading coefficient for the i i th y y variable on the j j th canonical variate.
5:     ifail – int64int32nag_int scalar
ifail = 0 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 ifail=1
On entry,nx < 1 nx<1 ,
orny < 1 ny<1 ,
orm < nx + ny m<nx+ny ,
ornnx + ny nnx+ny ,
or mcv < min (nx,ny) mcv < min (nx,ny) ,
orldz < n ldz<n ,
orldcvx < nx ldcvx<nx ,
orldcvy < ny ldcvy<ny ,
or lde < min (nx,ny) lde < min (nx,ny) ,
ornxny nxny  and
iwk < n × nx + nx + ny + max ((5 × (nx1) + nx × nx),n × ny) iwk<n×nx+nx+ny+max ( (5× (nx-1) +nx×nx) ,n×ny) ,
ornx < ny nx<ny  and
iwk < n × ny + nx + ny + max ((5 × (ny1) + ny × ny),n × nx) iwk<n×ny+nx+ny+max ( (5× (ny-1) +ny×ny) ,n×nx) ,
orweight'U' weight'U'  or 'W' 'W' ,
ortol < 0.0 tol<0.0 .
  ifail = 2 ifail=2
On entry,a weight = 'W' weight='W'  and value of wt < 0.0 wt<0.0 .
  ifail = 3 ifail=3
On entry,the number of x x  variables to be included in the analysis as indicated by isz is not equal to nx.
orthe number of y y  variables to be included in the analysis as indicated by isz is not equal to ny.
  ifail = 4 ifail=4
On entry,the effective number of observations is less than nx + ny + 1 nx+ny+1 .
  ifail = 5 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 ifail=6
A canonical correlation is equal to 1 1 . This will happen if the x x  and y y  variables are perfectly correlated.
W ifail = 7 ifail=7
On entry, the rank of the X X  matrix or the rank of the Y Y  matrix is 0 0 . This will happen if all the x x  or y y  variables are constants.

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

function nag_mv_canon_corr_example
z = [80, 58.4, 14, 21;
     75, 59.2, 15, 27;
     78, 60.3, 15, 27;
     75, 57.4, 13, 22;
     79, 59.5, 14, 26;
     78, 58.1, 14.5, 26;
     75, 58, 12.5, 23;
     64, 55.5, 11, 22;
     80, 59.2, 12.5, 22];
isz = [int64(-1);1;1;-1];
nx = int64(2);
ny = int64(2);
mcv = int64(2);
tol = 1e-06;
[e, ncv, cvx, cvy, ifail] = nag_mv_canon_corr(z, isz, nx, ny, mcv, tol)
 

e =

    0.9570    0.9159    0.8746   14.3914    4.0000    0.0061
    0.3624    0.1313    0.1254    0.7744    1.0000    0.3789


ncv =

                    2


cvx =

   -0.4261    1.0337
   -0.3444   -1.1136


cvy =

   -0.1415    0.1504
   -0.2384   -0.3424


ifail =

                    0


function g03ad_example
z = [80, 58.4, 14, 21;
     75, 59.2, 15, 27;
     78, 60.3, 15, 27;
     75, 57.4, 13, 22;
     79, 59.5, 14, 26;
     78, 58.1, 14.5, 26;
     75, 58, 12.5, 23;
     64, 55.5, 11, 22;
     80, 59.2, 12.5, 22];
isz = [int64(-1);1;1;-1];
nx = int64(2);
ny = int64(2);
mcv = int64(2);
tol = 1e-06;
[e, ncv, cvx, cvy, ifail] = g03ad(z, isz, nx, ny, mcv, tol)
 

e =

    0.9570    0.9159    0.8746   14.3914    4.0000    0.0061
    0.3624    0.1313    0.1254    0.7744    1.0000    0.3789


ncv =

                    2


cvx =

   -0.4261    1.0337
   -0.3444   -1.1136


cvy =

   -0.1415    0.1504
   -0.2384   -0.3424


ifail =

                    0



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–2013