Skip to content

Covariance: deviations together

Textbook

For jointly defined random variables $X,Y$ with finite second moments, covariance is $\operatorname{Cov}(X,Y)=\mathbb E[(X-\mathbb E[X])(Y-\mathbb E[Y])]$. Equivalently, $\operatorname{Cov}(X,Y)=\mathbb E[XY]-\mathbb E[X]\mathbb E[Y]$.

Deviations in the same direction produce a positive product; opposite directions produce a negative one. Averaging shows which contributions prevail. Covariance depends on scale and uses the product of the variables’ units; magnitudes cannot be compared without considering those units.

If $Y=2X$ and $X$ is equally likely to be 2, 4, or 6, then $\operatorname{Cov}(X,Y)=2\operatorname{Var}(X)=16/3$. Independence implies zero covariance, but zero covariance does not imply independence.

In a counterexample, $U$ takes $-1,0,1$ with equal probability and $V=U^2$. Then $\mathbb E[U]=\mathbb E[UV]=0$, giving zero covariance. Yet $U=0$ guarantees $V=0$, although $P(V=0)=1/3$. Dependence exists; positive and negative contributions merely cancel.

Expanding the centered product gives $XY-X\mathbb E[Y]-Y\mathbb E[X]+\mathbb E[X]\mathbb E[Y]$. Linearity of expectation and the constant means reduce these four terms to the shorter formula above. Adding a constant to one variable preserves its deviations and therefore its covariance. Multiplying one variable by a number $a$ multiplies covariance by $a$, so a negative rescaling reverses its sign.

Definitions and notation: Mathematics for Machine Learning.

Related concepts: Variance: the mean squared deviation, Statistical independence.

In plain language

Covariance compares paired measurements with their respective means. Deviations in the same direction produce a positive product, while opposite directions produce a negative one. The result combines that balance with probability weights, but zero can reflect cancellation rather than an absence of dependence. This bookkeeping neither explains causes nor detects every possible relationship; a zero balance can conceal plenty of activity.

Example

The constructed counterexample $V=U^2$ shows how zero covariance coexists with a deterministic relationship.

Covariance: deviations together

Linked values

Each of the three pairs has probability 1/3.

Step 1 of 4: Linked values

Read all steps
  1. Linked values

    Each of the three pairs has probability 1/3.

    U
    βˆ’101
    V
    101
  2. Centering

    Means are 0 and 2/3. Each is subtracted from the corresponding row.

    Deviations of U
    βˆ’101
    Deviations of V
    1/3currentβˆ’2/3current1/3current
  3. Products of deviations

    The outer products are opposite; the middle product is zero.

    Products
    βˆ’1/3excluded01/3included
  4. Dependence check

    Knowing U = 0 leaves only V = 0, making its probability 1.

    Remaining pair
    U = 0includedV = 0included
    Unconditional; conditional
    1/31current

At the outer outcomes, the deviation of $V$ is the same $1/3$, while the deviations of $U$ are opposite: βˆ’1 and 1. Their products cancel. The middle pair contributes zero because $U=0$, although its $V$ deviation is $-2/3$. Dividing by three is justified by the equal pair probabilities. Other weights would require weighted averaging, and that cancellation could no longer be assumed.

Covariance measures a balance of joint deviations. Establishing independence requires a stronger check.

The original text of this free article is published under CC BY-NC-ND 4.0.

Previous / next

Previous
Sample variance and the estimated mean
Next
Supervised classification
  • Natural Numbers: Counting Discrete Objects

    Which values count discrete objects, and why the zero convention must be stated.

    Read article
    Math
  • Integers: Counting on Both Sides of Zero

    Positive and negative integers, zero, and the limits of integer division.

    Read article
    Math
  • Rational Numbers: Ratios of Integers

    Numbers as ratios of integers: equivalent fractions and the nonzero denominator requirement.

    Read article
    Math