Tutorials › Multi-Omics Data Integration › Worked Example of Classical CCA

Canonical Correlation and Partial Least Squares · Tutorial 152 of 597

Worked Example of Classical CCA

Learn to calculate and interpret classical CCA on paired data, and verify the canonical correlations against the covariance-maximization problem.

Intermediate 12 min read

What You'll Learn

  • Set up the centered paired data and sample covariance matrices for classical CCA.
  • Find canonical weights and correlations when the within-block covariance matrices are identity matrices.
  • Distinguish canonical weights, canonical scores, loadings, and cross-loadings.
  • Verify a computed canonical correlation by checking the optimization over unit-variance scores.
  • Diagnose common problems involving scaling, signs, variable order, and paired observations.
  • Compare the purpose of CCA with two-block PLS and recognize limits of a small-sample example.

From Paired Measurements to Canonical Scores

Canonical correlation analysis (CCA) looks for linear combinations of two sets of measurements that are maximally correlated across the same observational units. In a multi-omics setting, the two blocks might be measurements from two assays on the same participants. The pairing matters: each row of one block must correspond to the same unit as the row in the other block.

The calculation has several linked outputs. Canonical weights define the linear combinations, canonical scores are the resulting values for each unit, and canonical correlations quantify the association between paired scores. Correlations between original variables and scores, often called canonical loadings, help describe how the variables relate to those combinations.

Definition: Let \(X\) and \(Y\) be centered data matrices with \(n\) paired rows, and let \(S_{XX}\), \(S_{YY}\), and \(S_{XY}\) be their sample covariance matrices, using denominator \(n-1\). For weight vectors \(a\) and \(b\), the canonical scores are \(U=Xa\) and \(V=Yb\). The first canonical correlation is the maximum of \(\operatorname{corr}(Xa,Yb)\) over nonzero \(a,b\). Subsequent pairs maximize the same correlation subject to being uncorrelated with the earlier scores within each block.

For the classical calculation below, assume the rows are correctly paired and centered, and that both within-block sample covariance matrices are positive definite. Positive definiteness makes their inverses available and rules out exact linear dependencies among variables within a block. In a sample, the resulting quantities describe this dataset; interpreting them beyond it requires appropriate sampling assumptions and validation.

A Small Dataset and Its Covariances

Consider five hypothetical units measured on two variables in each of two blocks. The data are constructed from four centered, mutually orthogonal vectors \(a_1,a_2,c_1,c_2\), each with sample variance 1. Define the block variables by \(x_1=a_1\), \(x_2=a_2\), \(y_1=0.8a_1+0.6c_1\), and \(y_2=0.6a_2+0.8c_2\). The following entries are rounded to three decimal places; the exact construction, not the rounded display, determines the calculations.

Unit\(x_1\)\(x_2\)\(y_1\)\(y_2\)
11.4140.8161.4780.848
2-1.4140.816-0.7850.848
30.000-1.6330.346-0.622
40.0000.000-1.0390.358
50.0000.0000.000-1.431

Because the four generating vectors are centered, orthogonal, and have sample variance 1, the \(x\) variables each have variance 1 and covariance 0. The same holds for the \(y\) variables: for example, \(\operatorname{var}(y_1)=0.8^2+0.6^2=1\), and \(y_1\) and \(y_2\) use orthogonal generating vectors. The cross-block covariance is \(\operatorname{cov}(x_1,y_1)=0.8\), \(\operatorname{cov}(x_2,y_2)=0.6\), and the two off-diagonal covariances are 0. Thus, in the stated variable orders,

$$ S_{XX}=\begin{pmatrix}1&0\\0&1\end{pmatrix},\qquad S_{YY}=\begin{pmatrix}1&0\\0&1\end{pmatrix},\qquad S_{XY}=\begin{pmatrix}0.8&0\\0&0.6\end{pmatrix}. $$

This construction gives positive-definite within-block covariance matrices, as required. In practical work, the same matrices are calculated from centered observations; the rounded table can produce small departures from the exact values, so calculations should use unrounded data when available.

Worked Example: First Canonical Pair

Find the first canonical weights and correlation for the constructed data. Since both within-block covariance matrices are identity matrices, a score \(Xa\) has variance \(a^\mathsf{T}a\), and \(Yb\) has variance \(b^\mathsf{T}b\). We can impose unit score variances by requiring \(a^\mathsf{T}a=b^\mathsf{T}b=1\).

The covariance of the two scores is \(a^\mathsf{T}S_{XY}b\). Choosing \(a=(1,0)^\mathsf{T}\) and \(b=(1,0)^\mathsf{T}\) gives \(U_1=x_1\), \(V_1=y_1\), and

$$ \operatorname{corr}(U_1,V_1) =\frac{a^\mathsf{T}S_{XY}b} {\sqrt{(a^\mathsf{T}S_{XX}a)(b^\mathsf{T}S_{YY}b)}} =\frac{0.8}{\sqrt{1\cdot1}}=0.8. $$

The score correlation is 0.8, with no measurement units. These weights are not merely a convenient choice: the optimization check below shows that no other unit-variance linear combinations can attain a higher positive correlation. Changing both weight signs leaves the correlation unchanged; changing only one sign changes its sign.

Why These Weights Are Optimal

With identity within-block covariances, the denominator of the score correlation is 1 whenever both weight vectors have Euclidean length 1. Thus the optimization reduces to maximizing \(a^\mathsf{T}S_{XY}b\) subject to \(a^\mathsf{T}a=b^\mathsf{T}b=1\). For fixed \(a\), the maximum over unit-length \(b\) is \(\lVert S_{XY}^\mathsf{T}a\rVert\), by the Cauchy–Schwarz inequality. Maximizing this quantity over unit \(a\) yields the largest singular value of \(S_{XY}\). Here the singular values are 0.8 and 0.6, so 0.8 is the maximum possible first correlation.

More generally, when the within-block covariances are positive definite but not identity matrices, the classical CCA problem can be expressed using the matrix \(S_{XX}^{-1/2}S_{XY}S_{YY}^{-1/2}\). Its singular values are the canonical correlations. The inverse square roots rescale each block by its covariance structure; in this example they are identity matrices, so the singular values are directly those of \(S_{XY}\).

Key result: For classical CCA with positive-definite \(S_{XX}\) and \(S_{YY}\), canonical correlations are the singular values of \(S_{XX}^{-1/2}S_{XY}S_{YY}^{-1/2}\). The first is the largest singular value. For this example, they are 0.8 and 0.6.

Worked Example: Checking a Different Pair of Weights

Take unit-length weights \(a=(0.6,0.8)^\mathsf{T}\) and \(b=(0.8,0.6)^\mathsf{T}\). Each corresponding score has variance 1 because both within-block covariance matrices are identity matrices and each weight vector has squared length 1. The score covariance, and therefore the score correlation, is

$$ a^\mathsf{T}S_{XY}b =(0.6,0.8) \begin{pmatrix}0.8&0\\0&0.6\end{pmatrix} \begin{pmatrix}0.8\\0.6\end{pmatrix} =(0.6)(0.8)(0.8)+(0.8)(0.6)(0.6) =0.384+0.288=0.672. $$

This is below 0.8, as it must be under the optimization result. It verifies why one should not infer that a plausible pair of weights is canonical: the weights must achieve the maximum under the score-variance constraints.

Scores, Loadings, and Interpretation

A canonical weight is a coefficient used to form a score; a canonical loading is a correlation between an original variable and a score. These are different quantities, even though they can coincide in simple examples. Here the first scores are \(U_1=x_1\) and \(V_1=y_1\). Their within-block loadings, listed in the variable orders \(x_1,x_2\) and \(y_1,y_2\), are \((1,0)\) in each block: \(x_1\) correlates 1 with \(U_1\), \(x_2\) correlates 0, and correspondingly \(y_1\) correlates 1 with \(V_1\) while \(y_2\) correlates 0. The first pair’s cross-loadings are \(\operatorname{corr}(x_1,V_1)=0.8\), \(\operatorname{corr}(x_2,V_1)=0\), \(\operatorname{corr}(y_1,U_1)=0.8\), and \(\operatorname{corr}(y_2,U_1)=0\).

Worked Example: Second Pair and Variable Order

The second singular value is 0.6. Its weights are \(a_2=(0,1)^\mathsf{T}\) and \(b_2=(0,1)^\mathsf{T}\) in the established variable orders, giving \(U_2=x_2\) and \(V_2=y_2\). The score variances are both 1 and their covariance is 0.6, so \(\operatorname{corr}(U_2,V_2)=0.6\). The within-block loadings on this second pair, in the orders \(x_1,x_2\) and \(y_1,y_2\), are \((0,1)\) in each block. The cross-loadings are \(\operatorname{corr}(x_2,V_2)=0.6\) and \(\operatorname{corr}(y_2,U_2)=0.6\); the corresponding loadings for \(x_1\) and \(y_1\) are 0.

For example, unit 3 has second scores \(U_2=-1.633\) and \(V_2=-0.622\), using the rounded table. Those two values describe the unit’s positions on the second score axes; they do not imply that its individual-level association is 0.6. The canonical correlation summarizes the relationship across all paired units.

Canonical signs are arbitrary: replacing both weights in a pair by their negatives reverses both score axes but preserves the correlation and the substantive relationship. Variable order is not arbitrary when reporting loading vectors. In particular, reporting \((1,0)\) for the second pair would be wrong in the stated order; that vector would select the first variable, not the second.

Diagnostics, Alternatives, and Limits

Before interpreting a CCA calculation, check the pairing, centering, variable order, covariance calculations, and score variances. Recalculate score correlations from the actual scores and confirm that they match the reported canonical correlations, allowing for rounding. For subsequent pairs, check that each new score is uncorrelated with earlier scores within its own block. If a covariance matrix is singular or nearly singular, the classical inverse-based formulation may be undefined or unstable; a high apparent association can then reflect redundant variables or overfitting rather than reproducible shared structure.

A useful check is to compare the computed score correlation with the optimization value. In this example, the first computed correlation, 0.8, agrees with the largest singular value. A discrepancy would suggest an error in centering, covariance scaling, weight normalization, or variable order. Rounding a displayed data table and then recomputing from those rounded entries can also create small discrepancies, but not a substantial disagreement.

CCA and two-block PLS answer related but distinct optimization questions. CCA maximizes score correlation, normalizing by the within-block score variances; two-block PLS seeks directions of high cross-block covariance. In this example the within-block covariance matrices are identity matrices, so the first directions coincide and the leading cross-covariance is also 0.8. That coincidence is not a general equivalence: when within-block variances differ, the correlation normalization can produce different directions from covariance maximization.

This example is deliberately small and well-conditioned. It does not establish statistical significance, generalize to a population, or show that either block causes the other. With many variables and few paired units, classical CCA can fit sample-specific associations; stable interpretation then depends on suitable validation and other design choices. Association is also not evidence that a score represents a single biological mechanism.

  • Wrong reasoning: “The second pair’s loadings are \((1,0)\), because it is the first loading when I discuss that pair.”
    Correction: Keep the stated variable order fixed. For \(U_2=x_2\), the loadings on \(x_1,x_2\) are \((0,1)\); for \(V_2=y_2\), those on \(y_1,y_2\) are also \((0,1)\).
  • Wrong reasoning: “The weights look reasonable, so their correlation must be canonical.”
    Correction: Canonical weights solve a constrained optimization. Check their score variances and compare the resulting correlation with the relevant singular value.
  • Wrong reasoning: “A loading of 1 means the original variable and the other block’s score correlate 1.”
    Correction: A within-block loading is the correlation with the score formed from that same block. Here the first within-block loadings are 1, while the cross-loadings are 0.8.

Check Your Understanding

Use the covariance matrices and variable orders given above. Solutions are included for checking.

  1. What is the second canonical correlation, and which variables form its scores?
  2. For the first pair, what is the correlation between \(x_1\) and \(V_1\)? Is it the same as the within-block loading of \(x_1\) on \(U_1\)?
  3. Suppose both first-pair weight vectors are multiplied by \(-1\). What happens to the score correlation?
  4. Why is \(S_{XX}=S_{YY}=I\) helpful for checking the optimization in this example?
  5. Does the first canonical correlation establish a causal effect of one block on the other? Explain.

Solutions. (1) The second canonical correlation is 0.6, with scores \(U_2=x_2\) and \(V_2=y_2\). (2) \(\operatorname{corr}(x_1,V_1)=0.8\); it differs from the within-block loading \(\operatorname{corr}(x_1,U_1)=1\). (3) Both scores reverse sign, so their correlation remains 0.8. (4) Unit score variances correspond directly to unit-length weight vectors, making the maximum score covariance the largest singular value of \(S_{XY}\). (5) No. CCA describes association between linear combinations across paired units and, by itself, does not establish causation.

Clinical Biostats