In statistics, canonical-correlation analysis (CCA), also called canonical variates analysis, is a way of inferring information from cross-covariance matrices. If we have two vectors X = (X1, ..., Xn) and Y = (Y1, ..., Ym) of random variables, and there are correlations among the variables, then canonical-correlation analysis will find linear combinations of X and Y that have a maximum correlation with each other. T. R. Knapp notes that "virtually all of the commonly encountered parametric tests of significance can be treated as special cases of canonical-correlation analysis, which is the general procedure for investigating the relationships between two sets of variables." The method was first introduced by Harold Hotelling in 1936, although in the context of angles between flats the mathematical concept was published by Camille Jordan in 1875. CCA is important in multivariate statistics and multi-view learning, and a number of interpretations and extensions have been proposed, such as probabilistic CCA, sparse CCA, multi-view CCA, deep CCA, and DeepGeoCCA. Literature on the subject can on occasion be inconsistent with notation. These inconsistencies are noted in this article to help the reader make best use of the existing literature and techniques available. Like its sister method PCA, CCA can be viewed in population form (corresponding to random vectors and their covariance matrices) or in sample form (corresponding to datasets and their sample covariance matrices). These two forms are almost exact analogues of each other, which is why their distinction is often overlooked, but they can behave very differently in high dimensional settings. We next give explicit mathematical definitions for the population problem and highlight the different objects in the so-called canonical decomposition - understanding the differences between these objects is crucial for interpretation of the technique.
Population CCA definition via correlations Given two column vectors X=(x1,…,xn)T and Y=(y1,…,ym)T of random variables with finite second moments, one may define the cross-covariance ΣXY=cov(X,Y) to be the n×m matrix whose (i,j) entry is the covariance cov(xi,yj). In practice, we would estimate the covariance matrix based on sampled data from X and Y (i.e. from a pair of data matrices). Canonical-correlation analysis seeks a sequence of vectors ak (ak∈ℝn) and bk (bk∈ℝm) such that the random variables akTX and bkTY maximize the correlation ρ=corr(akTX,bkTY). The (scalar) random variables U=a1TX and V=b1TY are the first pair of canonical variables. Then one seeks vectors maximizing the same correlation subject to the constraint that they are to be uncorrelated with the first pair of canonical variables; this gives the second pair of canonical variables. This procedure may be continued up to min{m,n} times.
(ak,bk)=argmaxa,bcorr(aTX,bTY) subject to cov(aTX,ajTX)=cov(bTY,bjTY)=0 for j=1,…,k−1 The sets of vectors ak,bk are called canonical directions or weight vectors or simply weights. The 'dual' sets of vectors ΣXXak,ΣYYbk are called canonical loading vectors or simply loadings; these are often more straightforward to interpret than the weights.
Computation
Derivation Let ΣXY be the cross-covariance matrix for any pair of (vector-shaped) random variables X and Y. The target function to maximize is
ρ=aTΣXYbaTΣXXabTΣYYb. The first step is to define a change of basis and define
c=ΣXX1/2a, d=ΣYY1/2b, where ΣXX1/2 and ΣYY1/2 can be obtained from the eigen-decomposition (or by diagonalization):
ΣXX1/2=VXDX1/2VX⊤,VXDXVX⊤=ΣXX, and
ΣYY1/2=VYDY1/2VY⊤,VYDYVY⊤=ΣYY. Thus
ρ=cTΣXX−1/2ΣXYΣYY−1/2dcTcdTd. By the Cauchy–Schwarz inequality,
(cTΣXX−1/2ΣXYΣYY−1/2)(d)≤(cTΣXX−1/2ΣXYΣYY−1/2ΣYY−1/2ΣYXΣXX−1/2c)1/2(dTd)1/2, ρ≤(cTΣXX−1/2ΣXYΣYY−1ΣYXΣXX−1/2c)1/2(cTc)1/2. There is equality if the vectors d and ΣYY−1/2ΣYXΣXX−1/2c are collinear. In addition, the maximum of correlation is attained if c is the eigenvector with the maximum eigenvalue for the matrix ΣXX−1/2ΣXYΣYY−1ΣYXΣXX−1/2 (see Rayleigh quotient). The subsequent pairs are found by using eigenvalues of decreasing magnitudes. Orthogonality is guaranteed by the symmetry of the correlation matrices. Another way of viewing this computation is that c and d are the left and right singular vectors of the correlation matrix of X and Y corresponding to the highest singular value.
Solution The solution is therefore:
c is an eigenvector of ΣXX−1/2ΣXYΣYY−1ΣYXΣXX−1/2 d is proportional to ΣYY−1/2ΣYXΣXX−1/2c Reciprocally, there is also:
d is an eigenvector of ΣYY−1/2ΣYXΣXX−1ΣXYΣYY−1/2 c is proportional to ΣXX−1/2ΣXYΣYY−1/2d Reversing the change of coordinates, we have that
a is an eigenvector of ΣXX−1ΣXYΣYY−1ΣYX, b is proportional to ΣYY−1ΣYXa; b is an eigenvector of ΣYY−1ΣYXΣXX−1ΣXY, a is proportional to ΣXX−1ΣXYb. The canonical variables are defined by:
U=cTΣXX−1/2X=aTX V=dTΣYY−1/2Y=bTY
Implementation CCA can be computed using singular value decomposition on a correlation matrix. It is available as a function in
MATLAB as canoncorr (also in Octave) R as the standard function cancor and several other packages, including candisc, CCA and vegan. CCP for statistical hypothesis testing in canonical correlation analysis. SAS as proc cancorr Python in the library scikit-learn, as cross decomposition and in statsmodels, as CanCorr. The CCA-Zoo library implements CCA extensions, such as probabilistic CCA, sparse CCA, multi-view CCA, and deep CCA. SPSS as macro CanCorr shipped with the main software Julia (programming language) in the MultivariateStats.jl package. CCA computation using singular value decomposition on a correlation matrix is related to the cosine of the angles between flats. The cosine function is ill-conditioned for small angles, leading to very inaccurate computation of highly correlated principal vectors in finite precision computer arithmetic. To fix this trouble, alternative algorithms are available in
SciPy as linear-algebra function subspace_angles MATLAB as FileExchange function subspacea
Hypothesis testing Each row can be tested for significance with the following method. Since the correlations are sorted, saying that row i is zero implies all further correlations are also zero. If we have p independent observations in a sample and ρ^i is the estimated correlation for i=1,…,min{m,n}. For the ith row, the test statistic is:
… excerpt ends here. Continue reading the full article.