Lecture 18

Variance, Covariance, and Correlation


Grace Tompkins

Last modified — 02 Dec 2026

Learning Outcomes

By the end of this lecture, students are anticipated to be able to:

  • Calculate variance and covariance from continuous and discrete random variables/distributions

  • Utilize properties of variance and covariance

1 Variance

Variance

The variance is a measure of the spread of the distribution of \(X\) around its mean \(\mathbb{E}[X]\).

The variance of a random variable \(X\) is defined by \[ \begin{aligned} \sigma^2_X &= \operatorname{Var}(X) \\ &= \mathbb{E}[(X - \mathbb{E}[X])^2] &\text{(this is the ``definition"...)}\\ &= \mathbb{E}[X^2] - \mathbb{E}[X]^2 & \text{(... but this version is often easier for calculations)} \end{aligned} \]

  • Careful here: \(\mathbb{E}[X]\) is a number, not a random variable.
  • Note that \(g(X) = (X - \mathbb{E}[X])^2\) is a function of \(X\), so we can compute \(\operatorname{Var}(X)\) using the definition of expected value.

Variance

  • The “units” of \(\operatorname{Var}(X)\) are the square of the units of \(X\), so sometimes we want to look at the spread of the distribution in the original units.

The standard deviation of a random variable \(X\) is defined by \[\sigma_X = \sqrt{\operatorname{Var}(X)}.\]

Properties of variance

(Where the variance exists.)

Scaling
For any \(a \in {\mathbb{R}}\), \(\operatorname{Var}(aX) = a^2 \operatorname{Var}(X)\).
Shift invariance
For any \(a \in {\mathbb{R}}\), \(\operatorname{Var}(X + a) = \operatorname{Var}(X)\).
Non-negativity
\(\operatorname{Var}(X) \ge 0\).
Relationship between \(\operatorname{Var}(X)\) and \(\mathbb{E}(X^2)\)
\[\begin{aligned} \operatorname{Var}(X) &= \mathbb{E}[(X - \mathbb{E}[X])^2] \\ &= \mathbb{E}[X^2 - 2X\mathbb{E}[X] + (\mathbb{E}[X])^2] \\ &= \mathbb{E}[X^2] - 2\mathbb{E}[X]\mathbb{E}[X] + (\mathbb{E}[X])^2 \\ &= \mathbb{E}[X^2] - (\mathbb{E}[X])^2.\\ \Longrightarrow \operatorname{Var}(X) &\le \mathbb{E}[X^2]. \end{aligned}\]

Variance

Recall if \(X \sim Unif(L,R)\), then \[f_X(x; L, R) = \frac{1}{R-L}I_{[L,R]}(x)\]

Let \(X \sim {\mathrm{Unif}}(0,1)\). Find \(\operatorname{Var}(X)\).

Variance

Variance

Variance

Let \(X \sim {\mathrm{Exp}}(\lambda)\). Find \(\operatorname{Var}(X)\).

You may use the fact that \(\mathbb{E}[X] = 1/\lambda\) and that \(\Gamma(z) = (z-1)!\) for integer \(z > 1\).

Variance

Variance

2 Covariance and Correlation

Covariance

If we have two random variables \(X\) and \(Y\), we can quantify the linear relationship between them using covariance.

The covariance between two random variables \(X\) and \(Y\) is defined by \[\operatorname{Cov}(X, Y) = \mathbb{E}[(X - \mathbb{E}[X])(Y - \mathbb{E}[Y])].\]

Easier calculation
\[\operatorname{Cov}(X, Y) = \mathbb{E}[XY] - \mathbb{E}[X]\mathbb{E}[Y].\]
  • \(\operatorname{Cov}(X, Y)\) is a scalar-valued function of \(X\) and \(Y\).
  • If \(\operatorname{Cov}(X, Y) > 0\), then \(X\) and \(Y\) tend to increase together.

Covariance

We can compute the covariance using the joint PMF/PDF of \(X\) and \(Y\).: \[\begin{aligned} \operatorname{Cov}(X, Y) &= \sum_{x} \sum_{y} (x - \mathbb{E}[X])(y - \mathbb{E}[Y]) p_{X,Y}(x, y).\\ \operatorname{Cov}(X, Y) &= \int_{-\infty}^\infty \int_{-\infty}^\infty (x - \mathbb{E}[X])(y - \mathbb{E}[Y]) f_{X,Y}(x, y) \, \mathsf{d}x \, \mathsf{d}y. \end{aligned}\]

Properties of covariance

Linearity
For any \(a, b, c \in {\mathbb{R}}\), and random variables \(X\), \(Y\), and \(Z\), \[\begin{aligned} \operatorname{Cov}(a X + b Y, c Z ) &= ac \operatorname{Cov}(X, Z) + bc \operatorname{Cov}(Y, Z). \end{aligned}\]
For any \(d, e \in {\mathbb{R}}\), and random variables \(X\) and \(Z\), \[\begin{aligned} \operatorname{Cov}(X +d, Z + e) &= \operatorname{Cov}(X, Z) \end{aligned}\]
Independence
If \(X\) and \(Y\) are independent, then \(\operatorname{Cov}(X, Y) = 0\). The converse is false.

Covariance

Let \(X\) be the number of heads in 5 tosses of a fair coin, and let \(Y\) be the number of tails in the same 5 tosses.

  1. Find \(\operatorname{Cov}(X, Y)\).

Hint: If \(Z\sim {\mathrm{Binom}}(n, \theta)\), then \(\operatorname{Var}(Z) = n\theta(1-\theta)\).

  1. Let \(Z = 3X+2\). What is \(Cov(Z, Y)\)?

Covariance

Variance, Covariance, and Sums

Let \(X\) and \(Y\) be random variables with finite variances.

  • \[\operatorname{Var}(X + Y) = \operatorname{Var}(X) + \operatorname{Var}(Y) + 2\operatorname{Cov}(X, Y).\]
  • If \(X\) and \(Y\) are independent, then \[\operatorname{Var}(X + Y) = \operatorname{Var}(X) + \operatorname{Var}(Y).\]
  • More generally, if \(X_1, \ldots, X_n\) are independent random variables with finite variances, then \[\operatorname{Var}\left(\sum_{i=1}^n X_i\right) = \sum_{i=1}^n \operatorname{Var}(X_i).\]

Correlation

Covariance is not a standardized measure of the relationship between \(X\) and \(Y\).

For example, if we multiply \(X\) by 100, then \(\operatorname{Cov}(X, Y)\) will also be multiplied by 100.

The correlation between two random variables \(X\) and \(Y\) is defined by \[\rho_{XY} = \operatorname{Corr}(X, Y) = \frac{\operatorname{Cov}(X, Y)}{\sigma_X \sigma_Y}.\]

  • The correlation is a standardized measure of the linear relationship between \(X\) and \(Y\).
  • We’ll see later that \(-1 \le \rho_{XY} \le 1\).

Returning to the heads or tails example, we have that \[\begin{aligned} \rho_{XY} &= \frac{\operatorname{Cov}(X, Y)}{\sigma_X \sigma_Y} = \frac{-5/4}{\sqrt{5/4} \sqrt{5/4}} = -1. \end{aligned}\]

Correlation

Let X and Y be discrete random variables with the following joint distribution:

P(X, Y) Y = 2 Y = 4
X = 1 0.2 0.3
X = 3 0.1 0.4

Hint: \(\sigma_X=1\) and \(\sigma_Y = 0.92\).

Calculate the correlation between \(X\) and \(Y\).

Correlation

Reminders:

  • Midterm 2 is in class on Friday November 20 (testing sections 2.4 (continuous RV/distributions) to 3.2 (expected values))

  • Practice problems have been posted on the website.

  • Cheat sheet rules:

    • MUST BE HAND WRITTEN! No photo copies, typed, or tablet-written and printed sheets allowed
    • 8.5 inches x 11 inches or less
    • You can have one (1) single page, and can write on both sides
  • Calculator rules:

    • scientific, non-graphing, non-programmable, non-wifi-ing