Canonical correlation#Solution

{{Machine learning|Dimensionality reduction}}

{{short description|Way of inferring information from cross-covariance matrices}}

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.{{Cite book | doi = 10.1007/978-3-540-72244-1_14 | chapter = Canonical Correlation Analysis | title = Applied Multivariate Statistical Analysis | pages = 321–330 | year = 2007 | isbn = 978-3-540-72243-4 | first1 = Wolfgang | last1 = Härdle| first2 = Léopold | last2 = Simar| citeseerx = 10.1.1.324.403 }} 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."{{Cite journal | last1 = Knapp | first1 = T. R. | title = Canonical correlation analysis: A general parametric significance-testing system | doi = 10.1037/0033-2909.85.2.410 | journal = Psychological Bulletin | volume = 85 | issue = 2 | pages = 410–416 | year = 1978 }} The method was first introduced by Harold Hotelling in 1936,{{Cite journal | last1 = Hotelling | first1 = H. | author-link1 = Harold Hotelling| title = Relations Between Two Sets of Variates | doi = 10.1093/biomet/28.3-4.321 | journal = Biometrika | volume = 28 | issue = 3–4 | pages = 321–377 | year = 1936 | jstor = 2333955}} although in the context of angles between flats the mathematical concept was published by Camille Jordan in 1875.{{cite journal

|last=Jordan

|first=C.

|author-link=Camille Jordan

|date=1875

|title=Essai sur la géométrie à n dimensions

|journal=Bull. Soc. Math. France

|volume=3

|pages=103

|url=http://www.numdam.org/item?id=BSMF_1875__3__103_2

}}

CCA is now a cornerstone of multivariate statistics and multi-view learning, and a great number of interpretations and extensions have been proposed, such as probabilistic CCA, sparse CCA, multi-view CCA, deep CCA,{{Cite journal |last=Andrew |first=Galen |last2=Arora |first2=Raman |last3=Bilmes |first3=Jeff |last4=Livescu |first4=Karen |date=2013-05-26 |title=Deep Canonical Correlation Analysis |url=https://proceedings.mlr.press/v28/andrew13.html |journal=Proceedings of the 30th International Conference on Machine Learning |language=en |publisher=PMLR |pages=1247–1255}} and DeepGeoCCA.{{Cite book |author=Ju |first1=Ce |url=https://openreview.net/pdf?id=PnR1MNen7u |title=Deep Geodesic Canonical Correlation Analysis for Covariance-Based Neuroimaging Data |last2=Kobler |first2=Reinmar J |last3=Tang |first3=Liyao |last4=Guan |first4=Cuntai |last5=Kawanabe |first5=Motoaki |publisher=The Twelfth International Conference on Learning Representations (ICLR 2024, spotlight) |year=2024}} Unfortunately, perhaps because of its popularity, the literature can be inconsistent with notation, we attempt to highlight such inconsistencies 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.{{Cite web |title=Statistical Learning with Sparsity: the Lasso and Generalizations |url=https://hastie.su.domains/StatLearnSparsity/ |access-date=2023-09-12 |website=hastie.su.domains}} 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 = (x_1, \dots, x_n)^T and Y = (y_1, \dots, y_m)^T of random variables with finite second moments, one may define the cross-covariance \Sigma _{XY} = \operatorname{cov}(X, Y) to be the n \times m matrix whose (i, j) entry is the covariance \operatorname{cov}(x_i, y_j). 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 a_k (a_k \in\mathbb R^n) and b_k (b_k \in\mathbb R^m) such that the random variables a_k^T X and b_k^T Y maximize the correlation \rho = \operatorname{corr}(a_k^T X, b_k^T Y). The (scalar) random variables U = a_1^T X and V = b_1^T Y 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.

: (a_k,b_k) = \underset{a,b}\operatorname{argmax} \operatorname{corr}(a^T X, b^T Y) \quad\text{ subject to } \operatorname{cov}(a^T X, a_j^T X) = \operatorname{cov}(b^T Y, b_j^T Y) = 0 \text{ for } j=1, \dots, k-1

The sets of vectors a_k, b_k are called canonical directions or weight vectors or simply weights. The 'dual' sets of vectors \Sigma_{XX}a_k, \Sigma_{YY} b_k are called canonical loading vectors or simply loadings; these are often more straightforward to interpret than the weights.{{Cite journal |last1=Gu |first1=Fei |last2=Wu |first2=Hao |date=2018-04-01 |title=Simultaneous canonical correlation analysis with invariant canonical loadings |url=https://doi.org/10.1007/s41237-017-0042-8 |journal=Behaviormetrika |language=en |volume=45 |issue=1 |pages=111–132 |doi=10.1007/s41237-017-0042-8 |issn=1349-6964}}

Computation

=Derivation=

Let \Sigma _{XY} be the cross-covariance matrix for any pair of (vector-shaped) random variables X and Y. The target function to maximize is

:

\rho = \frac{a^T \Sigma _{XY} b}{\sqrt{a^T \Sigma _{XX} a} \sqrt{b^T \Sigma _{YY} b}}.

The first step is to define a change of basis and define

:

c = \Sigma _{XX} ^{1/2} a,

:

d = \Sigma _{YY} ^{1/2} b,

where \Sigma_{XX}^{1/2} and \Sigma_{YY}^{1/2} can be obtained from the eigen-decomposition (or by diagonalization):

:

\Sigma _{XX} ^{1/2} = V_X D_X^{1/2} V_X^\top,\qquad V_X D_X V_X^\top = \Sigma_{XX},

and

:

\Sigma _{YY} ^{1/2} = V_Y D_Y^{1/2} V_Y^\top,\qquad V_Y D_Y V_Y^\top = \Sigma_{YY}.

Thus

:

\rho = \frac{c^T \Sigma _{XX} ^{-1/2} \Sigma _{XY} \Sigma _{YY} ^{-1/2} d}{\sqrt{c^Tc} \sqrt{d^Td}}.

By the Cauchy–Schwarz inequality, ...can someone check the this, particularly the term to the right of "(d) leq"?

:

\left(c^T \Sigma _{XX} ^{-1/2} \Sigma _{XY} \Sigma _{YY} ^{-1/2} \right) (d) \leq \left(c^T \Sigma _{XX} ^{-1/2} \Sigma _{XY} \Sigma _{YY} ^{-1/2} \Sigma _{YY} ^{-1/2} \Sigma _{YX} \Sigma _{XX} ^{-1/2} c \right)^{1/2} \left(d^T d \right)^{1/2},

:

\rho \leq \frac{\left(c^T \Sigma _{XX}^{-1/2} \Sigma _{XY} \Sigma _{YY}^{-1} \Sigma _{YX} \Sigma_{XX}^{-1/2} c \right)^{1/2}}{\left(c^T c \right)^{1/2}}.

There is equality if the vectors d and \Sigma_{YY}^{-1/2} \Sigma_{YX} \Sigma_{XX}^{-1/2} c are collinear. In addition, the maximum of correlation is attained if c is the eigenvector with the maximum eigenvalue for the matrix \Sigma_{XX}^{-1/2} \Sigma_{XY} \Sigma_{YY}^{-1} \Sigma_{YX} \Sigma_{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 \Sigma_{XX}^{-1/2} \Sigma_{XY} \Sigma_{YY}^{-1} \Sigma_{YX} \Sigma_{XX}^{-1/2}
  • d is proportional to \Sigma _{YY}^{-1/2} \Sigma_{YX} \Sigma_{XX}^{-1/2} c

Reciprocally, there is also:

  • d is an eigenvector of \Sigma_{YY}^{-1/2} \Sigma_{YX} \Sigma_{XX}^{-1} \Sigma_{XY} \Sigma_{YY}^{-1/2}
  • c is proportional to \Sigma_{XX}^{-1/2} \Sigma_{XY} \Sigma_{YY}^{-1/2} d

Reversing the change of coordinates, we have that

  • a is an eigenvector of \Sigma_{XX}^{-1} \Sigma_{XY} \Sigma_{YY}^{-1} \Sigma_{YX},
  • b is proportional to \Sigma_{YY}^{-1} \Sigma_{YX} a;
  • b is an eigenvector of \Sigma _{YY}^{-1} \Sigma_{YX} \Sigma_{XX}^{-1} \Sigma_{XY},
  • a is proportional to \Sigma_{XX}^{-1} \Sigma_{XY} b.

The canonical variables are defined by:

:U = c^T \Sigma_{XX}^{-1/2} X = a^T X

:V = d^T \Sigma_{YY}^{-1/2} Y = b^T Y

=Implementation=

CCA can be computed using singular value decomposition on a correlation matrix.{{Cite journal | last1 = Hsu | first1 = D. | last2 = Kakade | first2 = S. M. | last3 = Zhang | first3 = T. | doi = 10.1016/j.jcss.2011.12.025 | title = A spectral algorithm for learning Hidden Markov Models | journal = Journal of Computer and System Sciences | volume = 78 | issue = 5 | pages = 1460 | year = 2012 | url = http://www.cs.mcgill.ca/~colt2009/papers/011.pdf| arxiv = 0811.4413| s2cid = 220740158 }} It is available as a function in{{Cite journal | last1 = Huang | first1 = S. Y. | last2 = Lee | first2 = M. H. | last3 = Hsiao | first3 = C. K. | doi = 10.1016/j.jspi.2008.10.011 | title = Nonlinear measures of association with kernel canonical correlation analysis and applications | journal = Journal of Statistical Planning and Inference | volume = 139 | issue = 7 | pages = 2162 | year = 2009 | url = http://www.stat.sinica.edu.tw/syhuang/papersdownload/KCCA-080906.pdf | access-date = 2015-09-04 | archive-date = 2017-03-13 | archive-url = https://web.archive.org/web/20170313203427/http://www.stat.sinica.edu.tw/syhuang/papersdownload/KCCA-080906.pdf | url-status = dead }}

  • MATLAB as [http://www.mathworks.co.uk/help/stats/canoncorr.html canoncorr] ([https://sourceforge.net/p/octave/statistics/ci/default/tree/inst/canoncorr.m also] in Octave)
  • R as the standard function [http://stat.ethz.ch/R-manual/R-devel/library/stats/html/cancor.html cancor] and several other packages, including [https://cran.r-project.org/package=candisc candisc], [https://cran.r-project.org/web/packages/CCA/index.html CCA] and [https://cran.r-project.org/web/packages/vegan/index.html vegan]. [https://cran.r-project.org/web/packages/CCP/index.html CCP] for statistical hypothesis testing in canonical correlation analysis.
  • SAS as [https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_cancorr_toc.htm proc cancorr]
  • Python in the library scikit-learn, as [http://scikit-learn.org/stable/modules/cross_decomposition.html cross decomposition] and in statsmodels, as [https://devdocs.io/statsmodels/generated/statsmodels.multivariate.cancorr.cancorr CanCorr]. The CCA-Zoo library {{Cite journal |last1=Chapman |first1=James |last2=Wang |first2=Hao-Ting |date=2021-12-18 |title=CCA-Zoo: A collection of Regularized, Deep Learning based, Kernel, and Probabilistic CCA methods in a scikit-learn style framework |journal=Journal of Open Source Software |language=en |volume=6 |issue=68 |pages=3823 |doi=10.21105/joss.03823 |issn=2475-9066|doi-access=free |bibcode=2021JOSS....6.3823C }} 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 [https://github.com/JuliaStats/MultivariateStats.jl 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{{Citation

| last1 = Knyazev

| first1 = A.V.

| last2 = Argentati

| first2 = M.E.

| title = Principal Angles between Subspaces in an A-Based Scalar Product: Algorithms and Perturbation Estimates

| journal = SIAM Journal on Scientific Computing

| volume = 23

| issue = 6

| pages = 2009–2041

| year = 2002

| doi = 10.1137/S1064827500377332

| bibcode = 2002SJSC...23.2008K

| citeseerx = 10.1.1.73.2914

}} are available in

  • SciPy as [https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.subspace_angles.html linear-algebra function subspace_angles]
  • MATLAB as [https://www.mathworks.com/matlabcentral/fileexchange/55-subspacea-m 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 \widehat{\rho}_i is the estimated correlation for i = 1,\dots, \min\{m,n\}. For the ith row, the test statistic is:

:\chi^2 = - \left( p - 1 - \frac{1}{2}(m + n + 1)\right) \ln \prod_{j = i}^{\min\{m,n\}} (1 - \widehat{\rho}_j^2),

which is asymptotically distributed as a chi-squared with (m - i + 1)(n - i + 1) degrees of freedom for large p.{{Cite book

| author = Kanti V. Mardia, J. T. Kent and J. M. Bibby

| title = Multivariate Analysis

| year = 1979

| publisher = Academic Press

}} Since all the correlations from \min\{m,n\} to p are logically zero (and estimated that way also) the product for the terms after this point is irrelevant.

Note that in the small sample size limit with p < n + m then we are guaranteed that the top m + n - p correlations will be identically 1 and hence the test is meaningless.Yang Song, Peter J. Schreier, David Ram´ırez, and Tanuj Hasija Canonical correlation analysis of high-dimensional data with very small sample support {{ArXiv|1604.02047}}

Practical uses

A typical use for canonical correlation in the experimental context is to take two sets of variables and see what is common among the two sets.{{cite book|last= Sieranoja|first=S.|author2=Sahidullah, Md| author3=Kinnunen, T.| author4= Komulainen, J.| author5= Hadid, A.|title=2018 IEEE 3rd International Conference on Signal and Image Processing (ICSIP) |chapter=Audiovisual Synchrony Detection with Optimized Audio Features |date=July 2018|pages=377–381 |doi=10.1109/SIPROCESS.2018.8600424 |isbn=978-1-5386-6396-7 |s2cid=51682024 |url=http://urn.fi/urn:nbn:fi-fe2020041415345 |chapter-url=http://cs.joensuu.fi/pages/tkinnu/webpage/pdf/audiovisual_synchrony_2018.pdf}} For example, in psychological testing, one could take two well established multidimensional personality tests such as the Minnesota Multiphasic Personality Inventory (MMPI-2) and the NEO. By seeing how the MMPI-2 factors relate to the NEO factors, one could gain insight into what dimensions were common between the tests and how much variance was shared. For example, one might find that an extraversion or neuroticism dimension accounted for a substantial amount of shared variance between the two tests.

One can also use canonical-correlation analysis to produce a model equation which relates two sets of variables, for example a set of performance measures and a set of explanatory variables, or a set of outputs and set of inputs. Constraint restrictions can be imposed on such a model to ensure it reflects theoretical requirements or intuitively obvious conditions. This type of model is known as a maximum correlation model.{{Cite journal | last1 = Tofallis | first1 = C. | title = Model Building with Multiple Dependent Variables and Constraints | doi = 10.1111/1467-9884.00195 | journal = Journal of the Royal Statistical Society, Series D | volume = 48 | issue = 3 | pages = 371–378 | year = 1999 | arxiv = 1109.0725| s2cid = 8942357 }}

Visualization of the results of canonical correlation is usually through bar plots of the coefficients of the two sets of variables for the pairs of canonical variates showing significant correlation. Some authors suggest that they are best visualized by plotting them as heliographs, a circular format with ray like bars, with each half representing the two sets of variables.{{Cite book | last1 = Degani | first1 = A. | last2 = Shafto | first2 = M. | last3 = Olson | first3 = L. | doi = 10.1007/11783183_11 | chapter = Canonical Correlation Analysis: Use of Composite Heliographs for Representing Multiple Patterns | title = Diagrammatic Representation and Inference | series = Lecture Notes in Computer Science | volume = 4045 | pages = 93 | year = 2006 | isbn = 978-3-540-35623-3 | chapter-url = http://ti.arc.nasa.gov/m/profile/adegani/Composite_Heliographs.pdf| citeseerx = 10.1.1.538.5217 }}

Examples

Let X = x_1 with zero expected value, i.e., \operatorname{E}(X)=0.

  1. If Y = X, i.e., X and Y are perfectly correlated, then, e.g., a=1 and b=1, so that the first (and only in this example) pair of canonical variables is U = X and V = Y =X.
  2. If Y = -X, i.e., X and Y are perfectly anticorrelated, then, e.g., a=1 and b=-1, so that the first (and only in this example) pair of canonical variables is U = X and V = -Y =X.

We notice that in both cases U =V, which illustrates that the canonical-correlation analysis treats correlated and anticorrelated variables similarly.

Connection to principal angles

Assuming that X = (x_1, \dots, x_n)^T and Y = (y_1, \dots, y_m)^T have zero expected values, i.e., \operatorname{E}(X)=\operatorname{E}(Y)=0, their covariance matrices \Sigma _{XX} =\operatorname{Cov}(X,X) = \operatorname{E}[X X^T] and \Sigma _{YY} =\operatorname{Cov}(Y,Y) = \operatorname{E}[Y Y^T] can be viewed as Gram matrices in an inner product for the entries of X and Y, correspondingly. In this interpretation, the random variables, entries x_i of X and y_j of Y are treated as elements of a vector space with an inner product given by the covariance \operatorname{cov}(x_i, y_j); see Covariance#Relationship to inner products.

The definition of the canonical variables U and V is then equivalent to the definition of principal vectors for the pair of subspaces spanned by the entries of X and Y with respect to this inner product. The canonical correlations \operatorname{corr}(U,V) is equal to the cosine of principal angles.

Whitening and probabilistic canonical correlation analysis

CCA can also be viewed as a special whitening transformation where the random vectors X and Y are simultaneously transformed in such a way that the cross-correlation between the whitened vectors X^{CCA} and Y^{CCA} is diagonal.{{cite journal | last1 = Jendoubi | first1 = T. | last2 = Strimmer | first2 = K. | title = A whitening approach to probabilistic canonical correlation analysis for omics data integration | journal = BMC Bioinformatics | volume = 20 | issue = 1 | pages = 15 | year = 2018 | arxiv = 1802.03490 | doi = 10.1186/s12859-018-2572-9 | pmid = 30626338 | pmc = 6327589 | doi-access = free }}

The canonical correlations are then interpreted as regression coefficients linking X^{CCA} and Y^{CCA} and may also be negative. The regression view of CCA also provides a way to construct a latent variable probabilistic generative model for CCA, with uncorrelated hidden variables representing shared and non-shared variability.{{cite journal |last1=Jendoubi |first1=Takoua |last2=Strimmer |first2=Korbinian |title=A whitening approach to probabilistic canonical correlation analysis for omics data integration |journal=BMC Bioinformatics |date=9 January 2019 |volume=20 |issue=1 |pages=15 |doi=10.1186/s12859-018-2572-9 |doi-access=free |pmid=30626338 |pmc=6327589 |language=en |issn=1471-2105}}

See also

References

{{Reflist|30em}}