Covariance and Correlation
Suppose you measure the height and weight of many adults. Or the temperature and ice-cream sales on many days. You suspect these pairs of numbers move together. But "moving together" is a vague idea until it is made precise. Covariance and correlation are the two standard tools that quantify this tendency. They measure how two random variables increase or decrease together. This turns an intuitive notion of association into a computable, provably well-behaved number. The idea matters because almost every question in applied probability and statistics involving more than one random variable reduces at some point to computing or bounding a covariance. This includes portfolio risk, regression, principal component analysis, and the variance of a sum of dependent random variables. Covariance is the natural "cross term" that appears whenever we expand . Correlation is its normalized, unit-free version. It is bounded between and , which allows comparison across different scales of measurement. The big picture is that covariance is a bilinear form on random variables. It is much like an inner product on a vector space. This algebraic structure is exactly what makes it tractable. It obeys clean symmetry and linearity rules. These rules let us compute variances of complicated linear combinations from simple pairwise pieces. Correlation is the corresponding "cosine of the angle" between two random variables in this inner-product geometry. The Cauchy–Schwarz inequality underlies its boundedness. This article gives the rigorous definitions of covariance and correlation. It proves bilinearity and the Cauchy–Schwarz-based bound . It proves that independence implies zero covariance. It also carefully establishes, with an explicit counterexample, that the converse fails. The article works through two fully computed non-trivial examples. It closes by connecting to the variance of sums, the bivariate normal law, and conditional expectation.
- Covariance measures the linear co-movement of and , in the units of times units of .
- Correlation is the unit-free, scale-invariant version, always in .
- Covariance is symmetric and bilinear: , and it distributes over sums.
- Independence forces , but zero covariance does not imply independence — only for jointly Gaussian pairs (with finite variance) does the converse hold.
- if and only if is an exact affine (linear) function of almost surely.
- Key idea: covariance is a bilinear "inner product" on centered random variables, and correlation is the cosine of the angle it induces — capturing only linear dependence, not dependence in general.
Where this lives today
Covariance and correlation are foundational far beyond introductory probability. In finance, the covariance matrix of asset returns drives Markowitz portfolio optimization, where minimizing portfolio variance for a target return requires exactly the bilinear expansion of Variance of Sums across many assets. In statistics, the correlation coefficient underlies simple linear regression, where the least-squares slope is , and its square, , is the coefficient of determination reported in every regression output. In machine learning and signal processing, covariance matrices are diagonalized via principal component analysis to find directions of maximal variance in high-dimensional data, and whitening/decorrelation transforms rely on the bilinear algebra proved above. In physics and engineering, covariance appears in error propagation formulas and in the study of correlated noise processes; in cryptography and coding theory, correlation attacks exploit statistical dependence between key bits and outputs, a direct if adversarial use of the same coefficient. The natural next steps are to see how covariance structures the The Bivariate Normal Distribution (where uncorrelated truly means independent), how Conditional Expectation refines the "explained variance" idea underlying correlation, and how bilinearity generalizes to the multivariate covariance matrix used throughout multivariate statistics.
:::faq[Why does covariance use instead of just ?] Centering removes the effect of the means so covariance measures co-variation around the average, not the raw size of and . If and were both shifted upward by adding large constants, would change substantially even though the underlying association pattern is unchanged, since constants don't create or destroy dependence. The centered version is invariant under such shifts (this is exactly the affine-shift property proved in the Theorem), which is what makes it a meaningful measure of joint variability rather than an artifact of location.
Ask the tutor: How does covariance generalize to a covariance matrix for random vectors, and why must that matrix always be positive semi-definite?
Let and be random variables on a common probability space , each with finite second moment, i.e. and . Write , . The covariance of and is
This quantity is well-defined and finite: by the Cauchy–Schwarz inequality for the inner product on square-integrable random variables,
so the expectation defining converges absolutely. An equivalent and often more convenient computational formula is
obtained by expanding the product and using linearity of expectation. If (i.e. and are each non-degenerate, with strictly positive variance), the correlation coefficient of and is
If or (one variable is almost surely constant), is left undefined, since the variable carries no linear variability to correlate. and are called uncorrelated if , equivalently (when defined).
Intuition
Think of a centered random variable as a "vector" in the space of square-integrable random variables, with inner product . The covariance is exactly the inner product of the centered variables and . The variance is the squared length of in this geometry. Correlation is then the cosine of the angle between the two centered vectors:
A cosine is always in ; a value near means the vectors point in nearly the same direction (strong positive linear association), near means nearly opposite directions, and near means the vectors are nearly orthogonal — no linear relationship, though a strong nonlinear one may still be hiding. This geometric picture also explains why covariance is bilinear: inner products are linear in each argument, so covariance inherits linearity in and in separately, which is what makes it algebraically tractable when we expand variances of sums. It is crucial to keep in mind that this is a picture of linear association only. Two variables can be perfectly, deterministically dependent — for instance with symmetric about — and still have zero covariance, because the "angle" geometry only sees linear alignment, not general functional dependence.
Let be random variables with finite second moments on , and let . Then: 1. Symmetry: . 2. Relation to variance: . 3. Bilinearity:
and by symmetry the analogous identity holds in the second argument. 4. Affine shifts: . 5. Variance of a sum:
6. Independence implies uncorrelatedness: if and are independent, then . 7. Cauchy–Schwarz bound: if , then
8. Equality case: if and only if there exist constants and such that almost surely; moreover corresponds to and to .
We prove each part in turn, using only linearity of expectation and previously established parts.
(1) Symmetry. By definition, . Since multiplication of real numbers is commutative, pointwise on , so the two expectations coincide.
(2) Relation to variance. Set : , the standard definition of variance.
(3) Bilinearity. Let ; then by linearity of expectation, and pointwise
Hence
By linearity of expectation this equals
All expectations above are finite by the Cauchy–Schwarz argument in the Definition applied to each pair, so no convergence issues arise, and linearity of expectation for two finite-mean random variables is legitimate to invoke.
(4) Affine shifts. Apply bilinearity in the first slot with the constant absorbed: since a constant has for any (as is deterministic, its "centered" version is identically ), bilinearity (part 3, applied twice, once in each argument) gives
using by the same constant argument applied in the second slot.
(5) Variance of a sum. By part (2) and bilinearity applied twice (first in the outer argument, then distributing over in the inner argument),
By symmetry (part 1), , and by part (2), , . Substituting gives the claimed identity.
(6) Independence implies uncorrelatedness. If , then for any Borel-measurable functions with and , independence gives the factorization (this is the standard product rule for expectations of independent random variables, established from the definition of independence and Fubini's theorem for the joint law ). Taking , (valid here since implies by Cauchy–Schwarz), we get
Hence, by the computational formula in the Definition,
(7) Cauchy–Schwarz bound. Let , ; these are square-integrable centered random variables. The Cauchy–Schwarz inequality for the bilinear form states
(Proof of this inequality: for every real , , a quadratic in that is nonnegative for all ; a real quadratic for all requires discriminant , i.e. , giving the stated bound. If the inequality is immediate since then a.s. and both sides vanish.) Applying this with as above, and noting , :
Dividing both sides by gives .
(8) Equality case. From the proof of Cauchy–Schwarz above, equality holds if and only if the discriminant is exactly zero, which happens if and only if the quadratic attains the value at its minimizing . But for a random variable means almost surely (a nonnegative-expectation random variable, namely , has expectation zero iff it is a.s. — this is the standard fact that with forces a.s., proved by noting for every by Markov's inequality, and taking a union over ). Thus a.s., i.e.
which rearranges to a.s., an exact affine relation; solving for in terms of (since when , which holds here as ) gives a.s. for constants , . Conversely, if a.s. with , then by part (4), , and so ; hence
This confirms exactly in the affine case, with sign matching the sign of , completing the equivalence.
∎Worked examples
Example 1 — A discrete joint distribution with negative, non-trivial correlation. Let take values in with joint probability mass function given by the table:
(These sum to : .) Marginals. , , . Check: . , . Check: . Means.
Second moments.
Cross moment. ; only terms with contribute:
Covariance.
Correlation.
So and are negatively correlated: as tends to be larger, tends to be smaller (probability mass leans toward when , and toward when ). The moderate magnitude reflects a real but far-from-deterministic linear association, consistent with from the Theorem proved above.
Example 2 — Covariance of a linear combination via bilinearity, with a non-independent, non-Gaussian pair. Let (each value with probability ), and let be an independent random variable with . Define
Note depends on multiplicatively through the noise , so are dependent but not simply affinely related, and is not independent of 's relationship to in a simple additive-noise sense — this is a genuinely asymmetric, non-symmetric construction. We want using bilinearity rather than brute-force joint enumeration. Setup via bilinearity. Write . Then
by bilinearity (Theorem, part 3), applied with for the term absorbed into itself. So we need and . Moments of . Values each with probability :
Cross term . First compute . Since and ,
Next, (again since , so , and functions of independent variables are independent) . So . Assembling.
Correlation. We also need . Write ; since always,
using . So
Also . So
Then
So even though is built from multiplied by symmetric noise (making the relationship highly nonlinear and far from a clean line), the pair is moderately positively correlated () — because larger pushes both (in magnitude and, on the positive side, in value) and the variance of upward, while the mean structure still leaves a net positive linear alignment. This illustrates bilinearity as a genuine computational tool, reducing a seemingly complicated joint calculation to variance and cross-term pieces.
The Theorem proved above shows independence uncorrelatedness (part 6). The converse is false in general; dropping the hypothesis "independent" and replacing it merely with "uncorrelated" breaks the implication that the variables carry no relationship at all.
Construction. Let be a random variable with , and define . Then is a deterministic function of — about as dependent as two random variables can be, since knowing tells you exactly — yet we show . Moments.
Covariance.
So and are uncorrelated. But they are not independent: for instance,
and , so the independence factorization fails outright — indeed is a deterministic (hence maximally dependent, non-invertible) function of .
Why this happens. Covariance only detects linear co-movement: it is built from , a single bilinear pairing. The relationship is symmetric under while the "linear detector" is antisymmetric under the same flip, so the positive and negative correlations exactly cancel in the expectation, even though the dependence (in fact, a deterministic functional link) is total. This is precisely why the theorem's hypothesis "independent" cannot be weakened to "uncorrelated" when concluding a strong dependence statement — uncorrelated is a strictly weaker, purely linear notion. (The converse does hold under an added hypothesis: if is jointly Gaussian, then uncorrelated implies independent — a special extra structural assumption absent here.)
Scope, edge cases & common traps
| Situation | What holds | What can fail |
|---|---|---|
| independent, finite variances | always | — |
| uncorrelated | Independence need not hold (see counterexample) | |
| jointly Gaussian, uncorrelated | Independence does hold (special extra theorem) | Requires joint normality, not just each marginal Gaussian |
| (constant a.s.) | for all | is undefined, not |
| a.s., | exactly | Sign of matches sign of |
| Infinite variance () | Covariance may not exist | Cauchy–Schwarz step in Definition breaks down |
The mathematician behind it
Origins · 1 minFrancis Galton and how this was discovered
Francis Galton, studying heredity of physical traits such as height, discovered "regression toward mediocrity" — the tendency of offspring measurements to lie closer to the population mean than their parents' measurements. To quantify the strength of association between paired measurements (parent height and child height, for instance), Galton and his collaborator, the mathematician Karl Pearson, developed the correlation coefficient in the form used today. Pearson's 1896 paper gave the coefficient its now-standard formula and statistical treatment, building directly on Galton's graphical and geometric insights about regression lines through scatter data.
Is correlation the same as causation?
No. A nonzero correlation only records a statistical linear association between two random variables observed together; it says nothing about which, if either, causes the other, or whether both are driven by a third confounding variable. Classic examples include ice cream sales and drowning incidents, both driven by hot weather rather than one causing the other. Establishing causation requires additional structure — randomized experiments, causal graphical models, or instrumental variables — well beyond what the covariance/correlation formalism alone can supply.
Why is correlation always between and ?
This follows directly from the Cauchy–Schwarz inequality applied to the centered random variables and , treated as vectors under the inner product . Cauchy–Schwarz states that the inner product of two vectors is bounded in absolute value by the product of their norms, and dividing covariance by is precisely dividing by that product of norms. The proof (given in the Theorem's proof) uses that a real quadratic in , namely for all , must have non-positive discriminant.
Can covariance be negative, and what does that mean?
Yes; negative covariance means that when tends to be above its mean, tends to be below its mean, and vice versa — an inverse linear tendency. For example, in Worked Example 1 above, reflects that larger values of shift probability mass toward the smaller value of . The sign of covariance (and correlation) records the direction of linear association, while the magnitude (especially after normalizing to correlation) records its strength.
Does zero correlation mean the variables carry no information about each other?
Not necessarily — it only means there's no linear relationship. The counterexample with symmetric shows a case of exact deterministic dependence with zero correlation, because the dependence is purely nonlinear (quadratic) and the linear detector cannot see it. To capture more general dependence, statisticians use tools like mutual information, distance correlation, or rank correlations (Spearman's, Kendall's), which are sensitive to monotonic or general dependence rather than only linear dependence.
How does correlation relate to the slope of a regression line?
In simple linear regression of on , minimizing over yields the optimal slope , which can be rewritten as . So correlation is the slope rescaled to be unit-free: it tells you the strength of the best linear fit independent of the measurement units of and , while the regression slope itself carries the units of per unit of .
Why does the theorem require finite variance, and what if variances are infinite?
Finite variance guarantees, via Cauchy–Schwarz, that , so the defining expectation for covariance converges absolutely and the quantity is well-defined. If (as for certain heavy-tailed distributions such as some Pareto or Cauchy-type laws), the covariance may fail to exist altogether, and the entire Cauchy–Schwarz argument underlying collapses since one side of the inequality is infinite. In such heavy-tailed settings, robust alternatives like rank-based correlations are typically used instead.