Canonical Correlation Analysis (CCA): Relating Two Sets of Variables
Canonical correlation analysis (CCA) tests and describes the relationship between two sets of variables. Instead of asking how one variable relates to another, it asks: “How strongly is this group of measures related to that group of measures, and which variables drive the link?”
This guide explains what CCA is, why it is needed, its main elements, how to interpret each part of the output, how to run it in SPSS, R, Python and StatFas, and how to report it in APA 7.
1. What Is Canonical Correlation Analysis?
Take two sets of variables measured on the same cases. Set X might be three measures of study habits; set Y might be four exam scores. CCA finds a weighted combination of the X variables (U1) and a weighted combination of the Y variables (V1) whose Pearson correlation is as large as possible. That correlation is the first canonical correlation.
It then finds a second pair (U2, V2) that is as correlated as possible subject to being uncorrelated with the first pair, and so on. Each pair is a canonical function (or dimension). CCA is the general case of familiar methods:
- One variable in each set → ordinary Pearson correlation.
- One variable in one set → multiple regression (the canonical correlation is the multiple R).
- One set is dummy-coded groups → MANOVA and discriminant analysis (see MANOVA).
2. Why Is CCA Needed?
Use CCA when your research question is about the link between two groups of variables and neither group is a single outcome.
- Avoids many separate tests. Correlating every X with every Y produces a large table of overlapping correlations and inflates the Type I error rate. CCA gives one multivariate test of the whole relationship.
- Handles overlap within sets. Variables inside a set are usually correlated. CCA works with them jointly instead of pretending they are independent.
- Reveals structure. The loadings show which variables define each dimension, for example “body size” versus “bill shape”.
- Typical uses: psychology (personality traits and behaviours), education (teaching measures and learning outcomes), biology and ecology (morphology and environment), health (symptoms and biomarkers), marketing (attitudes and purchase behaviour), and neuroscience or genomics (brain activity and behaviour).
If one set is a clear single outcome, multiple regression is simpler. If you want to summarise one set only, use PCA. If you want to test a latent-variable theory, see SEM.
3. Main Elements of CCA
| Element | What it is | How to use it |
|---|---|---|
| Canonical variates (U, V) | Weighted sums of the variables in set X (U) and set Y (V). Every case gets a score on each. | The new, combined variables whose correlation is maximised. |
| Canonical function | One pair of variates (Ui, Vi). The number of functions = size of the smaller set. | Each function is a separate dimension of association, uncorrelated with the others. |
| Canonical correlation (rc) | The Pearson correlation between Ui and Vi. Values fall in descending order. | Strength of the link for that function. |
| Squared canonical correlation (rc²) and eigenvalue | Shared variance between the two variates. It is the eigenvalue (λ) of the matrix Rxx−1RxyRyy−1Ryx. | The effect size of a single function. |
| Wilks’ lambda (Λ) and F test | Λ = ∏(1 − rc²) over the functions tested. Function k and all later ones are tested together, using Rao’s F (or Bartlett’s χ²). | Decides how many functions are significant. 1 − Λ is the full-model effect size. |
| Standardized canonical coefficients | Weights on the z-scored variables used to build each variate. | Show each variable’s unique contribution, but are unstable when variables are correlated. |
| Structure coefficients (canonical loadings) | Correlation between an observed variable and its own variate. | The main tool for naming a dimension. Loadings of about .30 to .40 or more are usually interpreted. |
| Cross-loadings | Correlation between an observed variable and the other set’s variate. | Shows how well a variable is predicted by the opposite set. |
| Variance extracted and redundancy index | Variance extracted = average squared loading of a set on its own variate. Redundancy = variance extracted × rc². | Share of one set’s variance explained by the other set. It is not symmetric. |
Λk = ∏i=km (1 − rc,i²) with χ² = −[n − 1 − (p + q + 1)/2] · ln Λk, df = (p − k + 1)(q − k + 1), where p and q are the set sizes, m = min(p, q) and n is the sample size.4. Assumptions and Sample Size
- Continuous variables. Ordinal items with many levels are often treated as continuous; nominal predictors must be dummy coded.
- Linearity between variables and between the variates.
- Multivariate normality for the significance tests (the estimates themselves do not need it). Check each variable with a normality test.
- Homoscedasticity (similar spread of one variable across the range of the others).
- No extreme outliers. They can create or hide a canonical function.
- No multicollinearity or singularity within a set. Very high correlations (for example above .90) between variables of the same set make the weights unstable; drop or combine such variables.
- Independent observations and no missing-data problem (CCA drops incomplete cases).
- Sample size. Common rules of thumb ask for at least 10 to 20 cases per variable, and more when you interpret several functions or want stable loadings.
5. Worked Example: Penguin Bills and Body Size
The Palmer penguins data (complete cases, N = 333) is also the built-in example in the StatFas CCA tool. Set X is the bill: bill length and bill depth (mm). Set Y is body size: flipper length (mm) and body mass (g). Question: how are bill dimensions related to body size?
The correlations inside and between the sets show why CCA helps: flipper length and body mass are strongly related (r = .87), and bill length and depth are negatively related (r = −.23).
| Function | rc | rc² | Wilks’ Λ | F | df | p |
|---|---|---|---|---|---|---|
| 1 to 2 | .79 | .62 | .377 | 103.48 | 4, 658 | < .001 |
| 2 | .09 | .01 | .993 | 2.48 | 1, 330 | .116 |
The first row tests all functions together; the second row tests whether function 2 adds anything after function 1. Only function 1 is significant, so we interpret function 1.
| Variable | Set | Standardized coefficient | Loading |
|---|---|---|---|
| Bill length | X | .70 | .83 |
| Bill depth | X | −.58 | −.73 |
| Flipper length | Y | 1.02 | 1.00 |
| Body mass | Y | −.03 | .87 |
The redundancy index for function 1 is .38 for the bill set given body size (38% of the variance in bill length and depth is explained by the body-size variate) and .54 for the body-size set given the bill (54%).
6. How to Interpret CCA Results, Step by Step
- Test the full model. Wilks’ Λ = .377, F(4, 658) = 103.48, p < .001. The two sets are related. The full-model effect size is 1 − Λ = .62.
- Decide how many functions to keep. Use the dimension tests: function 1 is significant, function 2 is not (p = .116). Keep one function.
- Judge the size of the relationship. rc = .79, so rc² = .62: the first pair of variates shares 62% of its variance.
- Name the dimension with the loadings. In the body-size set both flipper length (1.00) and body mass (.87) load highly: a “large body” variate. In the bill set, bill length loads positively (.83) and bill depth negatively (−.73): a “long, shallow bill” variate. Penguins with large bodies tend to have long, shallow bills.
- Check coefficients against loadings. Body mass has a coefficient near zero (−.03) but a high loading (.87). Because body mass and flipper length are so strongly correlated (r = .87), flipper length takes the weight. Do not conclude that body mass is unimportant; the loading shows it is strongly tied to the variate.
- Read redundancy. The bill set explains 54% of the body-size variance, and body size explains 38% of the bill variance. These are different because redundancy is asymmetric.
- Remember the sign is arbitrary. Reversing the signs of both variates of a function gives an equivalent solution. Interpret the pattern of signs, not the direction of one variable.
Association is not causation: CCA describes a relationship between sets and does not show which set causes the other.
7. How to Run CCA on StatFas
- Open the StatFas canonical correlation analysis tool.
- Upload your data file, or press Load example data (Palmer penguins).
- Tick the numeric variables of Set X and of Set Y. Optionally choose a grouping variable for the plots and a loading cut-off.
- Press Run canonical correlation analysis.
- Read the canonical correlations, Wilks’ lambda tests, standardized coefficients, structure coefficients, communalities, variance extracted and redundancy, plus the scatter plot of the first variate pair and the loadings chart.
- Copy the written APA 7 interpretation. A Word (.docx) file with the tables and figure is available after a free sign-up. Your data is analysed in your browser and is not uploaded.
8. How to Run CCA in SPSS, R and Python
SPSS
SPSS has no menu for CCA. Use the supplied macro or the MANOVA command in the Syntax Editor (File › New › Syntax).
Option A: CANCORR macro. Adjust the path to your SPSS installation folder.
INCLUDE 'C:\Program Files\IBM\SPSS Statistics\Samples\English\Canonical correlation.sps'.
CANCORR SET1 = bill_length_mm bill_depth_mm
/SET2 = flipper_length_mm body_mass_g.Option B: MANOVA. Variables before WITH form one set; variables after WITH form the other.
MANOVA bill_length_mm bill_depth_mm WITH flipper_length_mm body_mass_g
/PRINT = SIGNIF(MULTIV EIGEN DIMENR)
/DISCRIM = RAW STAN ESTIM COR ALPHA(.999)
/DESIGN.- In the output read Eigenvalues and Canonical Correlations for rc and eigenvalues.
- Read Dimension Reduction Analysis for Wilks’ Λ, F, df and p of each function.
- Read the standardized canonical coefficients and the correlations between variables and canonical variables (the loadings).
R
library(palmerpenguins)
library(CCP)
d <- na.omit(penguins[, c("bill_length_mm", "bill_depth_mm",
"flipper_length_mm", "body_mass_g")])
X <- scale(d[, c("bill_length_mm", "bill_depth_mm")])
Y <- scale(d[, c("flipper_length_mm", "body_mass_g")])
cc <- cancor(X, Y) # base R
cc$cor # canonical correlations
U <- X %*% cc$xcoef # canonical variate scores, set X
V <- Y %*% cc$ycoef # canonical variate scores, set Y
cor(X, U) # loadings, set X
cor(Y, V) # loadings, set Y
# Wilks' lambda tests (dimension reduction)
p.asym(cc$cor, N = nrow(X), p = 2, q = 2, tstat = "Wilks")Signs and scaling of xcoef and ycoef can differ from SPSS, but the canonical correlations and loadings agree up to sign.
Python
import numpy as np
from palmerpenguins import load_penguins
from statsmodels.multivariate.cancorr import CanCorr
from sklearn.cross_decomposition import CCA
from sklearn.preprocessing import StandardScaler
d = load_penguins().dropna()
X = d[["bill_length_mm", "bill_depth_mm"]]
Y = d[["flipper_length_mm", "body_mass_g"]]
# Canonical correlations and Wilks' lambda tests
cc = CanCorr(Y, X)
print(cc.cancorr)
print(cc.corr_test().summary())
# Variate scores and loadings
Xs, Ys = StandardScaler().fit_transform(X), StandardScaler().fit_transform(Y)
U, V = CCA(n_components=2).fit(Xs, Ys).transform(Xs, Ys)
load_x = [np.corrcoef(Xs[:, i], U[:, 0])[0, 1] for i in range(2)]
load_y = [np.corrcoef(Ys[:, i], V[:, 0])[0, 1] for i in range(2)]
print(load_x, load_y)9. How to Report CCA in APA 7
A canonical correlation analysis examined the relationship between bill dimensions (bill length, bill depth) and body size (flipper length, body mass) in 333 penguins. The full model was significant, Wilks’ Λ = .377, F(4, 658) = 103.48, p < .001, with a full-model effect size of 1 − Λ = .62. Dimension reduction analysis showed that only the first function was significant (rc = .79, rc² = .62); the second was not, F(1, 330) = 2.48, p = .116. For the first function, bill length (loading = .83) and bill depth (loading = −.73) were related to flipper length (loading = 1.00) and body mass (loading = .87). Penguins with larger bodies tended to have longer, shallower bills. The bill variate explained 54% of the variance in body size, and the body-size variate explained 38% of the variance in bill dimensions.
Report: the sample size, the full-model Λ with F, df and p, each interpreted function’s rc (and rc²), a table of standardized coefficients and loadings, and redundancy if it is relevant. State your loading cut-off.
10. Common Mistakes
- Interpreting only the standardized coefficients instead of the loadings.
- Interpreting functions that are not significant, or small functions with tiny rc².
- Treating the sign of a variate as meaningful on its own.
- Using too few cases for the number of variables, which makes weights unstable.
- Putting highly collinear variables in the same set.
- Reading redundancy as symmetric, or as a causal effect.
11. Related Searches
- canonical correlation analysis
- canonical correlation analysis example
- canonical variates and canonical loadings
- Wilks’ lambda canonical correlation
- redundancy index canonical correlation
- how to interpret canonical correlation
- canonical correlation SPSS syntax
- canonical correlation in R (cancor)
- canonical correlation Python statsmodels
- canonical correlation analysis online free
Frequently Asked Questions
What is canonical correlation analysis?
Canonical correlation analysis (CCA) is a multivariate method that measures the relationship between two sets of variables by finding pairs of weighted combinations, one from each set, that are as strongly correlated as possible.
Why use canonical correlation instead of many separate correlations?
Separate correlations ignore that variables within each set overlap, and they inflate the number of tests. CCA summarises the whole between-set relationship in a few uncorrelated dimensions with a single multivariate test.
How many canonical functions are there?
The number of canonical functions equals the number of variables in the smaller set. With 2 variables in one set and 3 in the other there are 2 functions.
What is a good canonical correlation?
There is no fixed cut-off. Judge the first canonical correlation by its square (r²c), the shared variance of the pair of variates, together with its significance, its loadings and the sample size.
What does Wilks’ lambda mean in CCA?
Wilks’ lambda (Λ) tests whether the canonical correlations from a given function onward are all zero. Values near 0 mean strong relationships; values near 1 mean none. 1 − Λ is the effect size of the full model.
What is the difference between canonical coefficients and canonical loadings?
Coefficients are the weights used to build each canonical variate and are unstable when variables are correlated. Loadings (structure coefficients) are correlations between each variable and its variate, and are the main basis for interpretation.
What is the redundancy index?
Redundancy is the proportion of variance in one set of variables that is explained by the canonical variates of the other set. It equals the average squared loading of the set multiplied by the squared canonical correlation, and it is not symmetric.
What sample size does canonical correlation need?
Common rules of thumb ask for at least 10 to 20 cases per variable. Larger samples make the weights and loadings more stable, especially when you interpret more than the first function.
What is the difference between CCA and PCA?
PCA summarises the variance within one set of variables. CCA looks for the strongest correlation between two sets of variables.
Can canonical correlation use categorical variables?
Predictors that are categorical must be dummy coded. With one set being group dummy codes, CCA is mathematically equivalent to MANOVA and discriminant analysis.
How do you run canonical correlation in SPSS, R and Python?
In SPSS use the CANCORR macro or MANOVA with the WITH keyword and DISCRIM. In R use cancor() from base R with CCP for the tests. In Python use statsmodels CanCorr or scikit-learn CCA.
Run It Now
Upload your data, pick the two variable sets and get the full output with an APA 7 write-up.
Related Guides
See the full overview of core statistical analyses or browse all free statistical tools.