How this calculation works
Canonical correlation finds linear combinations from two matched variable blocks that are maximally correlated. Both blocks are centered, their sample covariance matrices are whitened, and a small spectral problem produces paired weights. The page returns each supported canonical correlation and its variable weights rather than confusing the result with ordinary pairwise correlations.
M=Sxx^(−1/2) Sxy Syy^(−1/2); canonical correlations are singular values of M.A worked example
If the first block is one column 1,2,3,4,5,6 and the second is twice that column, their only canonical correlation is one. Whitened weights differ by scale, but the resulting canonical scores agree up to sign. There is one pair because each block has one variable.
Good to know
Positive-definite full-rank block covariances and more rows than combined variable count are required. At most six variables per block. No hypothesis-test p-values, missing-value deletion or causal interpretation. Zero-correlation weight pairs may be nonunique.
Reference: Scikit-learn canonical correlation analysis (opens in a new tab) ↗
Matched observations determine cross-covariance
Rows in the two blocks must refer to the same observations in the same order. Equal row counts alone do not establish that alignment. A mismatched ordering can create or destroy apparent association, and no numerical rank check can recover an unknown pairing between the records.
Centering each block removes its mean before the three covariance matrices are formed. Within-block covariance must be positive definite for the supported whitening operation. Duplicate columns or too few independent observations produce a singular problem and require deliberate dimension reduction before this calculator can proceed.
The Partial correlation controlling one variable calculator covers the nearby task. Canonical correlation relates two multivariate blocks rather than controlling one variable in a scalar pair.
Whitening makes the normalization explicit
Whitening turns within-block variance into an identity matrix, allowing the cross-block singular values to measure correlation on a consistent scale. The returned weights map back to the original centered columns. They therefore depend on variable units even when the canonical correlation itself does not.
Each nonzero canonical pair is normalized to unit within-block variance. If a canonical correlation is zero, its partner direction is not determined by division through that correlation, so the page leaves that weight undefined instead of fabricating a stable-looking vector from numerical noise.
Canonical association needs cautious interpretation
Maximizing sample correlation can overfit when the number of variables approaches the number of observations. The row-count and conditioning restrictions prevent some algebraic failures but do not establish out-of-sample performance. Validation on independent paired observations is a separate statistical task, beyond the reported in-sample spectral calculation.
The identical-column example verifies the endpoint correlation one without needing a significance approximation. General tests compare the whitened cross-covariance singular values and check weight normalization. These checks do not supply a causal direction between the blocks or replace a hypothesis test tailored to the sampling design.
Why whitening comes before pairing the two blocks
For centered blocks X and Y, canonical correlation chooses weights a and b that maximize corr(Xa,Yb). The variance constraints aᵀSxxa=1 and bᵀSyyb=1 prevent an arbitrary rescaling of either score from affecting the optimization. Whitening transforms each within-block covariance to the identity; the singular values of the cross-covariance in those coordinates then give the canonical correlations.
The returned weights refer to each original centered block, not simply to the whitened coordinates. Their units depend on the measurements. There are at most min(p,q) pairs when the blocks have p and q columns. A second pair is constructed subject to within-block orthogonality to earlier canonical scores; it is not obtained by deleting the variables with the largest first-pair weights.
Calculate a nonperfect one-column association
Use X=1;2;3;4 and Y=1;3;2;4. Both means are 2.5. Each centered sum of squares is 5, and the centered cross-product is 4. Ordinary correlation is therefore 4/√(5×5)=0.8. With a single column in each block, canonical correlation reduces to the magnitude of that correlation, so the displayed canonical correlation is 0.8.
If every Y observation is multiplied by ten, the score normalization changes the Y weight but leaves the correlation at 0.8. Reversing the sign of Y can be absorbed into a weight sign, which is why canonical correlations are conventionally nonnegative. Read the paired weights and score direction together rather than interpreting a negative raw association as a negative canonical correlation.
Separate weights from scientific importance
A large canonical correlation says that some linear combination in one block aligns with a linear combination in the other block in the supplied sample. It does not say that every variable is strongly related, that one block causes the other, or that the relation will persist on new data. Several correlated variables can produce unstable weights even when the paired score correlation changes little.
For substantive interpretation, examine how each original variable relates to its canonical score and how the weights change across reasonable samples. This page returns correlations and weights, not a complete inferential report with canonical loadings, redundancy indices or hypothesis tests. Avoid reporting any of those uncomputed quantities as if they were part of the output.
Prepare matched observations and diagnose rank failures
The two blocks must describe the same individuals or occasions in the same row order. Equal row counts alone do not establish that alignment. Decide how to handle missing measurements before entering data; independently removing rows from the two blocks can silently match different people. A subject identifier should be used for matching outside the numeric matrix, not entered as another quantitative variable.
Duplicate columns, a constant column or exact linear combinations make whitening singular. Removing a scientifically redundant column can resolve this, but regularized CCA is a different model and is not an implicit fallback here. The requirement for more rows than combined variables avoids an especially overfit configuration; it still does not establish that the sample is large enough for reliable interpretation.
A few questions, answered
Why reject singular covariance?
The supported whitening formula requires invertible within-block covariances; reduce redundant variables deliberately first.
Is a large canonical correlation causal?
No. It is an in-sample linear association between matched variable combinations.
Is CCA the same as correlating every pair of columns?
No. It optimizes pairs of linear combinations across whole blocks. Pairwise correlations alone do not impose the within-block variance and orthogonality constraints.
Can I put unmatched samples into the blocks?
No. Every X row must match the corresponding Y row. This calculator cannot infer matching identities from the numeric values.