Lecture 21

Conditional Expectations


Grace Tompkins

Last modified — 02 Dec 2026

Learning Outcomes

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

  • Calculate conditional expectations from discrete and continuous distributions

  • Use the laws of total expectation to calculate expectations of hierarchical models

1 Conditional Expectation

Conditional Expectation

If \(X\) and \(Y\) are two random variables, then the conditional expectation of \(X\) given \(Y = y\) is \[\begin{aligned} \mathbb{E}\left[ X | Y= y \right] &= \int_{-\infty }^{\infty } x f_{X|Y}\left( x | y \right) \mathsf{d}x, & \mathbb{E}\left[ X | Y= y \right] &= \sum_{x} x p_{X|Y}(x|y). \end{aligned}\]

  • This is the same definition we saw previously for expectation, just with the conditional distribution.

Conditional Expectation

Let \(X\) and \(Y\) be random variables with joint density \(f(x, y) = 2\) for \(0 < x < 1, 0 < y < x\). What is the conditional expectation of \(Y\) given \(X\)?

Conditional Expectation

Conditional Variance

If \(X\) and \(Y\) are two random variables, then the conditional variance of \(X\) given \(Y = y\) is \[\begin{aligned} \operatorname{Var}(X | Y = y ) &= \int_{-\infty }^{\infty } ( x - \mathbb{E}[X|Y=y] ) ^{2}f_{X|Y}\left( x|y \right) \mathsf{d}x,\\ \operatorname{Var}(X | Y = y ) &= \sum_{x} ( x - \mathbb{E}[X|Y=y] ) ^{2}p_{X|Y}(x|y). \end{aligned}\]

Conditional Variance

Let \(X\) and \(Y\) be random variables with joint density \(f(x, y) = 2\) for \(0 < x < 1, 0 < y < x\). What is the conditional variance of \(Y\) given \(X\)?

Conditional Variance

Conditional Expectation and Variance

Sometimes we are directly given information about the conditional distribution. If this is a “known” distribution, we can just use the properties of that distribution.

  • Let \(\Theta \sim {\mathrm{Unif}}(0, 1)\)
  • Let \(Y | \Theta \sim {\mathrm{Binom}}(n, \Theta)\)

What are \(\mathbb{E}[Y|\Theta]\) and \(\operatorname{Var}(Y|\Theta)\)?

Because the conditional expectation follows \({\mathrm{Binom}}(n, \Theta)\), we know:

  • \(\mathbb{E}[Y|\Theta] = n\Theta\) and
  • \(\operatorname{Var}(Y|\Theta) = n\theta(1-\Theta)\).

Conditional Expectation and Variance

Important

Quick knowledge check. Are conditional expectations and variances random variables?

Conditional Expectation and Variance

  • The properties of expectation and variance that we have seen before also hold for conditional expectation and variance.

But there are some additional properties as well because \(\mathbb{E}[X|Y]\) and \(\operatorname{Var}[X|Y]\) are themselves random variables, and have their own distributions.


Consider again \(Y | \Theta \sim {\mathrm{Binom}}(n, \Theta)\) and \(\Theta \sim {\mathrm{Unif}}(0, 1)\)

  • \(W = \mathbb{E}[Y|\Theta] = n\Theta\) is a random variable that depends on \(\Theta\).
  • But \(\Theta \sim {\mathrm{Unif}}(0, 1)\), so \(W \sim {\mathrm{Unif}}(0, n)\)!

This general set up is referred to as a hierarchical model.

Hierarchical Models

  1. We first draw \(\Theta\) from some distribution.
  2. Then we draw \(Y\) from a distribution that depends on \(\Theta\).
  3. We can find the distribution of \(Y | \Theta\) as well as those of its expectation.

Hierarchical Models

  • Let \(\Lambda \sim {\mathrm{Gam}}(1, 2)\).
  • Let \(X | \Lambda \sim {\mathrm{Exp}}(1/\Lambda)\).

Find the distribution of \(W = \mathbb{E}[X|\Lambda]\) and \(\mathbb{E}[W]\).

Hierarchical Models

Law of Total Expectation and Variance (Tower Property)

Let \(X\) and \(Y\) be two random variables. Then \(\mathbb{E}[X] = \mathbb{E}[\mathbb{E}[X|Y]]\)

You can prove this result in the discrete or continuous cases by starting with the definition of the conditional expectation.

We also have:

Let \(X\) and \(Y\) be two random variables. Then, \(\operatorname{Var}(X) = \mathbb{E}[\operatorname{Var}(X|Y)] + \operatorname{Var}(\mathbb{E}[X|Y]).\)

This shows that the variance of \(X\) can be decomposed into two parts: the expected value of the conditional variance of \(X\) given \(Y\), and the variance of the conditional expectation of \(X\) given \(Y\).

Law of Total Expectation and Variance (Tower Property)

Recall the previous exercise where

  • Let \(\Lambda \sim {\mathrm{Gam}}(1, 2)\).
  • Let \(X | \Lambda \sim {\mathrm{Exp}}(1/\Lambda)\).

We technically applied the tower property without knowing it!

\[ \begin{aligned} \mathbb{E}[W] &= \mathbb{E}[\mathbb{E}[X \ \vert\ \Lambda]]\\ &= \mathbb{E}\left[\frac{1}{1/\Lambda}\right] \text{ since } X \ \vert\ \Lambda \sim {\mathrm{Exp}}(1/\lambda) \\ &=\mathbb{E}\left[\Lambda\right]\\ &=\frac{1}{2} \text{ since } \Lambda \sim Gam(1,2) \end{aligned} \] Same result!

Law of Total Expectation and Variance (Tower Property)

Let \(X\) and \(U\) be random variables such that \(U \sim {\mathrm{Unif}}(0. 1)\), and \(\mathbb{E}[X\ \vert\ U] = 3U^2\). Find \(\mathbb{E}[X]\).

Law of Total Expectation and Variance (Tower Property)

Reminders:

  • Checkpoint 7 is on Friday Dec 4 (MGFS + conditional expectation)

Checkpoint 5

You may have:

  • HANDWRITTEN Cheat Sheet

  • Non-graphing, non-programmable calculator

  • Writing materials

Phones and laptops put away, please! You can have 20 minutes.