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, xx and yy. For a sample of nn observations on nxnx variables in a data matrix XX and nyny variables in a data matrix YY, 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 VV. If the rank of the data matrix XX is kxkx and the rank of the data matrix YY is kyky, and both XX and YY have had variable (column) means subtracted then the kxkx by kyky matrix VV is given by:
V = QxTQy,
V=QxTQy,
where QxQx is the first kxkx columns of the orthogonal matrix QQ either from the QRQR decomposition of XX if XX is of full column rank, i.e., kx = nxkx=nx:
X = QxRx
X=QxRx
or from the SVD of XX if kx < nxkx<nx:
X = QxDxPxT.
X=QxDxPxT.
Similarly QyQy is the first kyky columns of the orthogonal matrix QQ either from the QRQR decomposition of YY if YY is of full column rank, i.e., ky = nyky=ny:
Y = QyRy
Y=QyRy
or from the SVD of YY if ky < nyky<ny:
Y = QyDyPyT.
Y=QyDyPyT.
Let the SVD of VV be:
V = UxΔUyT
V=UxΔUyT
then the nonzero elements of the diagonal matrix ΔΔ, δiδi, for i = 1,2,,li=1,2,,l, are the ll canonical correlations associated with the ll 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 iith 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 ii 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 = kmini=kmin is not significant, then the remaining tests for i > kmini>kmin should be ignored.
The loadings for the canonical variates are calculated from the matrices UxUx and UyUy 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 ldznldzn.
z(i,j)zij must contain the iith observation for the jjth variable, for i = 1,2,,ni=1,2,,n and j = 1,2,,mj=1,2,,m.
Both xx and yy variables are to be included in z, the indicator array, isz, being used to assign the variables in z to the xx or yy sets as appropriate.
2:     isz(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint mnx + nymnx+ny.
isz(j)iszj indicates whether or not the jjth variable is included in the analysis and to which set of variables it belongs.
isz(j) > 0iszj>0
The variable contained in the jjth column of z is included as an xx variable in the analysis.
isz(j) < 0iszj<0
The variable contained in the jjth column of z is included as a yy variable in the analysis.
isz(j) = 0iszj=0
The variable contained in the jjth 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 xx variables in the analysis, nxnx.
Constraint: nx1nx1.
4:     ny – int64int32nag_int scalar
The number of yy variables in the analysis, nyny.
Constraint: ny1ny1.
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.0tol0.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.)
nn, the number of observations.
Constraint: n > nx + nyn>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.)
mm, the total number of variables.
Constraint: mnx + nymnx+ny.
3:     wt( : :) – double array
Note: the dimension of the array wt must be at least nn if weight = 'W'weight='W', and at least 11 otherwise.
If weight = 'W'weight='W', the first nn elements of wt must contain the weights to be used in the analysis.
If wt(i) = 0.0wti=0.0, the iith 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 nn.
Constraints:
  • wt(i)0.0wti0.0, for i = 1,2,,ni=1,2,,n;
  • the sum of weightsnx + ny + 1sum of weightsnx+ny+1.

Input Parameters Omitted from the MATLAB Interface

weight ldz lde ldcvx ldcvy wk iwk

Output Parameters

1:     e(lde,66) – double array
ldemin (nx,ny)ldemin(nx,ny).
The statistics of the canonical variate analysis.
e(i,1)ei1
The canonical correlations, δiδi, for i = 1,2,,li=1,2,,l.
e(i,2)ei2
The eigenvalues of ΣΣ, λi2λi2, for i = 1,2,,li=1,2,,l.
e(i,3)ei3
The proportion of variation explained by the iith canonical variate, for i = 1,2,,li=1,2,,l.
e(i,4)ei4
The χ2χ2 statistic for the iith canonical variate, for i = 1,2,,li=1,2,,l.
e(i,5)ei5
The degrees of freedom for χ2χ2 statistic for the iith canonical variate, for i = 1,2,,li=1,2,,l.
e(i,6)ei6
The significance level for the χ2χ2 statistic for the iith canonical variate, for i = 1,2,,li=1,2,,l.
2:     ncv – int64int32nag_int scalar
The number of canonical correlations, ll. This will be the minimum of the rank of XX and the rank of YY.
3:     cvx(ldcvx,mcv) – double array
ldcvxnxldcvxnx.
The canonical variate loadings for the xx variables. cvx(i,j)cvxij contains the loading coefficient for the iith xx variable on the jjth canonical variate.
4:     cvy(ldcvy,mcv) – double array
ldcvynyldcvyny.
The canonical variate loadings for the yy variables. cvy(i,j)cvyij contains the loading coefficient for the iith yy variable on the jjth canonical variate.
5:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry,nx < 1nx<1,
orny < 1ny<1,
orm < nx + nym<nx+ny,
ornnx + nynnx+ny,
or mcv < min (nx,ny) mcv < min(nx,ny) ,
orldz < nldz<n,
orldcvx < nxldcvx<nx,
orldcvy < nyldcvy<ny,
or lde < min (nx,ny) lde < min(nx,ny) ,
ornxnynxny 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 < nynx<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.0tol<0.0.
  ifail = 2ifail=2
On entry,a weight = 'W'weight='W' and value of wt < 0.0wt<0.0.
  ifail = 3ifail=3
On entry,the number of xx variables to be included in the analysis as indicated by isz is not equal to nx.
orthe number of yy variables to be included in the analysis as indicated by isz is not equal to ny.
  ifail = 4ifail=4
On entry,the effective number of observations is less than nx + ny + 1nx+ny+1.
  ifail = 5ifail=5
A singular value decomposition has failed to converge. See nag_eigen_real_triang_svd (f02wu). This is an unlikely error exit.
W ifail = 6ifail=6
A canonical correlation is equal to 11. This will happen if the xx and yy variables are perfectly correlated.
W ifail = 7ifail=7
On entry, the rank of the XX matrix or the rank of the YY matrix is 00. This will happen if all the xx or yy 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