1. Home
  2. Explore
  3. Mathematics
  4. Conditional Expectation and Variance

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Conditional Expectation and Variance

Conditional Expectation, Conditional Variance, and Probability Inequalities

Conditional expectation

A conditional distribution describes how a random variable behaves when another random variable is known. Since a conditional distribution is itself a valid probability distribution, its conditional expectation and conditional variance can be calculated.

Let XXX and YYY be jointly distributed random variables.

Conditional expectation for continuous variables

If XXX and YYY have joint density fX,Y(x,y)f_{X,Y}(x,y)fX,Y​(x,y) and marginal density fY(y)f_Y(y)fY​(y), then, for values of yyy where fY(y)>0f_Y(y)>0fY​(y)>0,

fX∣Y(x∣y)=fX,Y(x,y)fY(y).f_{X\mid Y}(x\mid y)=\frac{f_{X,Y}(x,y)}{f_Y(y)}.fX∣Y​(x∣y)=fY​(y)fX,Y​(x,y)​.

The conditional expectation of XXX given Y=yY=yY=y is

E[X∣Y=y]=∫−∞∞xfX∣Y(x∣y) dx=∫−∞∞xfX,Y(x,y)fY(y) dx.\mathbb{E}[X\mid Y=y] =\int_{-\infty}^{\infty} x f_{X\mid Y}(x\mid y)\,dx =\int_{-\infty}^{\infty}x\frac{f_{X,Y}(x,y)}{f_Y(y)}\,dx.E[X∣Y=y]=∫−∞∞​xfX∣Y​(x∣y)dx=∫−∞∞​xfY​(y)fX,Y​(x,y)​dx.

Conditional expectation for discrete variables

For discrete XXX and YYY,

E[X∣Y=y]=∑xx P(X=x∣Y=y)=∑xx P(X=x,Y=y)P(Y=y),\mathbb{E}[X\mid Y=y] =\sum_x x\,\mathbb{P}(X=x\mid Y=y) =\frac{\sum_x x\,\mathbb{P}(X=x,Y=y)}{\mathbb{P}(Y=y)},E[X∣Y=y]=∑x​xP(X=x∣Y=y)=P(Y=y)∑x​xP(X=x,Y=y)​,

provided P(Y=y)>0\mathbb{P}(Y=y)>0P(Y=y)>0.

The value of yyy is fixed when calculating E[X∣Y=y]\mathbb{E}[X\mid Y=y]E[X∣Y=y], but the result generally changes with yyy. Thus, E[X∣Y=y]\mathbb{E}[X\mid Y=y]E[X∣Y=y] is a function of yyy. When YYY is treated as a random variable, this function becomes the random variable E[X∣Y]\mathbb{E}[X\mid Y]E[X∣Y].

If XXX and YYY are independent, learning YYY does not change the distribution of XXX, so

E[X∣Y=y]=E[X].\mathbb{E}[X\mid Y=y]=\mathbb{E}[X].E[X∣Y=y]=E[X].

Example: two dice and their maximum

Let XXX and X1X_1X1​ be the results of two independent throws of a fair six-sided die. Each takes values 1,2,3,4,5,61,2,3,4,5,61,2,3,4,5,6, each with probability 16\frac{1}{6}61​. Define

Y=max⁡(X,X1).Y=\max(X,X_1).Y=max(X,X1​).

The pair (X,Y)(X,Y)(X,Y) is dependent: knowing the maximum restricts the possible value of XXX. For example, if Y=2Y=2Y=2, then XXX cannot be greater than 222.

Joint and marginal probabilities

For a fixed value yyy:

  • If x<yx<yx<y, the event X=x,  Y=yX=x,\;Y=yX=x,Y=y requires X1=yX_1=yX1​=y. Its probability is 136\frac{1}{36}361​.

  • If x=yx=yx=y, the event X=y,  Y=yX=y,\;Y=yX=y,Y=y occurs whenever X1≤yX_1\le yX1​≤y. There are yyy possible values of X1X_1X1​, so its probability is y36\frac{y}{36}36y​.

  • If x>yx>yx>y, the event is impossible.

Therefore, for y=1,…,6y=1,\ldots,6y=1,…,6,

P(Y=y)=2y−136.\mathbb{P}(Y=y)=\frac{2y-1}{36}.P(Y=y)=362y−1​.

The marginal probabilities of YYY are consequently

P(Y=1,…,6)=1,3,5,7,9,1136.\mathbb{P}(Y=1,\ldots,6) =\frac{1,3,5,7,9,11}{36}.P(Y=1,…,6)=361,3,5,7,9,11​.

In contrast, the marginal distribution of XXX remains uniform:

P(X=x)=16,x=1,…,6.\mathbb{P}(X=x)=\frac{1}{6},\qquad x=1,\ldots,6.P(X=x)=61​,x=1,…,6.

The marginal probability of Y=yY=yY=y is obtained by summing the joint probabilities over all possible xxx: there are y−1y-1y−1 outcomes with x<yx<yx<y, each of probability 136\frac{1}{36}361​, and one case with x=yx=yx=y, of probability y36\frac{y}{36}36y​.

Conditional distribution of XXX given Y=yY=yY=y

For x<yx<yx<y,

P(X=x∣Y=y)=1362y−136=12y−1.\mathbb{P}(X=x\mid Y=y) =\frac{\frac{1}{36}}{\frac{2y-1}{36}} =\frac{1}{2y-1}.P(X=x∣Y=y)=362y−1​361​​=2y−11​.

For x=yx=yx=y,

P(X=y∣Y=y)=y362y−136=y2y−1.\mathbb{P}(X=y\mid Y=y) =\frac{\frac{y}{36}}{\frac{2y-1}{36}} =\frac{y}{2y-1}.P(X=y∣Y=y)=362y−1​36y​​=2y−1y​.

Thus, conditional on the maximum being yyy, XXX can take values 1,…,y1,\ldots,y1,…,y. The values below yyy each have conditional probability 12y−1\frac{1}{2y-1}2y−11​, while the value yyy has probability y2y−1\frac{y}{2y-1}2y−1y​.

Conditional expectation in the dice example

Using the conditional probabilities,

E[X∣Y=y]=∑x=1y−1x+y22y−1=y(3y−1)2(2y−1).\mathbb{E}[X\mid Y=y] =\frac{\sum_{x=1}^{y-1}x+y^2}{2y-1} =\frac{y(3y-1)}{2(2y-1)}.E[X∣Y=y]=2y−1∑x=1y−1​x+y2​=2(2y−1)y(3y−1)​.

The resulting values are

E[X∣Y=1]=1,E[X∣Y=2]=53,E[X∣Y=3]=125,E[X∣Y=4]=227,E[X∣Y=5]=359,E[X∣Y=6]=5111.\begin{aligned} \mathbb{E}[X\mid Y=1]&=1,\\ \mathbb{E}[X\mid Y=2]&=\frac{5}{3},\\ \mathbb{E}[X\mid Y=3]&=\frac{12}{5},\\ \mathbb{E}[X\mid Y=4]&=\frac{22}{7},\\ \mathbb{E}[X\mid Y=5]&=\frac{35}{9},\\ \mathbb{E}[X\mid Y=6]&=\frac{51}{11}. \end{aligned}E[X∣Y=1]E[X∣Y=2]E[X∣Y=3]E[X∣Y=4]E[X∣Y=5]E[X∣Y=6]​=1,=35​,=512​,=722​,=935​,=1151​.​

These conditional expectations differ across values of YYY, illustrating that E[X∣Y]\mathbb{E}[X\mid Y]E[X∣Y] is generally a random variable.


Law of total expectation

A central result about conditional expectation is that averaging the conditional expectation over the distribution of the conditioning variable recovers the original expectation:

E[E[X∣Y]]=E[X].\mathbb{E}\big[\mathbb{E}[X\mid Y]\big]=\mathbb{E}[X].E[E[X∣Y]]=E[X].

This is also called the law of total expectation or the tower property.

For continuous variables, the equality follows by integrating over the joint density:

E[E[X∣Y]]=∫E[X∣Y=y]fY(y) dy=∫(∫xfX,Y(x,y)fY(y) dx)fY(y) dy=∫∫xfX,Y(x,y) dx dy=∫xfX(x) dx=E[X].\begin{aligned} \mathbb{E}\big[\mathbb{E}[X\mid Y]\big] &=\int \mathbb{E}[X\mid Y=y] f_Y(y)\,dy\\ &=\int\left(\int x\frac{f_{X,Y}(x,y)}{f_Y(y)}\,dx\right)f_Y(y)\,dy\\ &=\int\int x f_{X,Y}(x,y)\,dx\,dy\\ &=\int x f_X(x)\,dx\\ &=\mathbb{E}[X]. \end{aligned}E[E[X∣Y]]​=∫E[X∣Y=y]fY​(y)dy=∫(∫xfY​(y)fX,Y​(x,y)​dx)fY​(y)dy=∫∫xfX,Y​(x,y)dxdy=∫xfX​(x)dx=E[X].​

The discrete version follows by summing over the possible values of YYY.

Applying the law to the dice example

In the dice example, the values of E[X∣Y]\mathbb{E}[X\mid Y]E[X∣Y] occur with the probabilities of the corresponding values of YYY. Therefore,

E[E[X∣Y]]=1⋅136+53⋅336+125⋅536+227⋅736+359⋅936+5111⋅1136=1+5+12+22+35+5136=12636=72.\begin{aligned} \mathbb{E}\big[\mathbb{E}[X\mid Y]\big] &=1\cdot\frac{1}{36} +\frac{5}{3}\cdot\frac{3}{36} +\frac{12}{5}\cdot\frac{5}{36} +\frac{22}{7}\cdot\frac{7}{36}\\ &\quad+\frac{35}{9}\cdot\frac{9}{36} +\frac{51}{11}\cdot\frac{11}{36}\\ &=\frac{1+5+12+22+35+51}{36}\\ &=\frac{126}{36} =\frac{7}{2}. \end{aligned}E[E[X∣Y]]​=1⋅361​+35​⋅363​+512​⋅365​+722​⋅367​+935​⋅369​+1151​⋅3611​=361+5+12+22+35+51​=36126​=27​.​

Directly, XXX is uniform on {1,…,6}\{1,\ldots,6\}{1,…,6}, so

E[X]=1+2+3+4+5+66=72.\mathbb{E}[X]=\frac{1+2+3+4+5+6}{6}=\frac{7}{2}.E[X]=61+2+3+4+5+6​=27​.

The two calculations agree, as the law of total expectation requires.

The same result applies with the roles of XXX and YYY reversed. In this example,

E[Y]=∑y=16y2y−136=16136,\mathbb{E}[Y] =\sum_{y=1}^{6}y\frac{2y-1}{36} =\frac{161}{36},E[Y]=∑y=16​y362y−1​=36161​,

and hence E[E[Y∣X]]=E[Y]=16136\mathbb{E}[\mathbb{E}[Y\mid X]]=\mathbb{E}[Y]=\frac{161}{36}E[E[Y∣X]]=E[Y]=36161​.


Conditional variance and the law of total variance

The conditional variance measures the variability of XXX after the value of YYY is known. It is defined by

Var⁡(X∣Y)=E[X2∣Y]−(E[X∣Y])2.\operatorname{Var}(X\mid Y) =\mathbb{E}[X^2\mid Y]-\big(\mathbb{E}[X\mid Y]\big)^2.Var(X∣Y)=E[X2∣Y]−(E[X∣Y])2.

Because both conditional moments depend on YYY, conditional variance is generally also a random variable.

A key relationship is the law of total variance:

Var⁡(X)=E[Var⁡(X∣Y)]+Var⁡(E[X∣Y]).\operatorname{Var}(X) =\mathbb{E}[\operatorname{Var}(X\mid Y)] +\operatorname{Var}(\mathbb{E}[X\mid Y]).Var(X)=E[Var(X∣Y)]+Var(E[X∣Y]).

This separates the total variability in XXX into two components:

  • E[Var⁡(X∣Y)]\mathbb{E}[\operatorname{Var}(X\mid Y)]E[Var(X∣Y)] is the average variability remaining within the conditional distributions.

  • Var⁡(E[X∣Y])\operatorname{Var}(\mathbb{E}[X\mid Y])Var(E[X∣Y]) is the variability between the conditional means for different values of YYY.

Derivation

The conditional variance identity gives

E[Var⁡(X∣Y)]=E[E[X2∣Y]]−E[(E[X∣Y])2].\mathbb{E}[\operatorname{Var}(X\mid Y)] =\mathbb{E}[\mathbb{E}[X^2\mid Y]] -\mathbb{E}\big[(\mathbb{E}[X\mid Y])^2\big].E[Var(X∣Y)]=E[E[X2∣Y]]−E[(E[X∣Y])2].

The variance of the conditional expectation is

Var⁡(E[X∣Y])=E[(E[X∣Y])2]−(E[E[X∣Y]])2.\operatorname{Var}(\mathbb{E}[X\mid Y]) =\mathbb{E}\big[(\mathbb{E}[X\mid Y])^2\big] -\big(\mathbb{E}[\mathbb{E}[X\mid Y]]\big)^2.Var(E[X∣Y])=E[(E[X∣Y])2]−(E[E[X∣Y]])2.

Adding these expressions cancels the terms involving E[(E[X∣Y])2]\mathbb{E}[(\mathbb{E}[X\mid Y])^2]E[(E[X∣Y])2]. By the law of total expectation,

E[E[X2∣Y]]=E[X2]andE[E[X∣Y]]=E[X].\mathbb{E}[\mathbb{E}[X^2\mid Y]]=\mathbb{E}[X^2] \quad\text{and}\quad \mathbb{E}[\mathbb{E}[X\mid Y]]=\mathbb{E}[X].E[E[X2∣Y]]=E[X2]andE[E[X∣Y]]=E[X].

The sum therefore becomes

E[X2]−(E[X])2=Var⁡(X),\mathbb{E}[X^2]-(\mathbb{E}[X])^2 =\operatorname{Var}(X),E[X2]−(E[X])2=Var(X),

which proves the law of total variance.


Why probability inequalities are useful

Knowing a random variable’s expectation and variance does not usually determine its complete distribution. Different distributions can share the same mean and variance while having different shapes. However, expectation and variance can still provide bounds on the probability that a random variable is far from a chosen value or from its mean.

Chebyshev’s inequality gives a bound based on the second moment. Markov’s inequality provides a more general bound for nonnegative random variables or functions.


Chebyshev’s inequality

Let XXX have a finite expectation of (X−c)2(X-c)^2(X−c)2, let ccc be any real number, and let ε>0\varepsilon>0ε>0. Then

P(∣X−c∣≥ε)≤E[(X−c)2]ε2.\mathbb{P}(|X-c|\ge\varepsilon) \le \frac{\mathbb{E}[(X-c)^2]}{\varepsilon^2}.P(∣X−c∣≥ε)≤ε2E[(X−c)2]​.

The inequality bounds the probability that XXX is at least a distance ε\varepsilonε from ccc.

Proof

On the event ∣X−c∣≥ε|X-c|\ge\varepsilon∣X−c∣≥ε, squaring both sides gives

(X−c)2ε2≥1.\frac{(X-c)^2}{\varepsilon^2}\ge 1.ε2(X−c)2​≥1.

The quantity (X−c)2(X-c)^2(X−c)2 is nonnegative everywhere. Thus, when its expectation is integrated over the whole sample space, the contribution from the event ∣X−c∣≥ε|X-c|\ge\varepsilon∣X−c∣≥ε is at least the probability of that event:

E[(X−c)2]≥ε2P(∣X−c∣≥ε).\mathbb{E}[(X-c)^2] \ge \varepsilon^2\mathbb{P}(|X-c|\ge\varepsilon).E[(X−c)2]≥ε2P(∣X−c∣≥ε).

Dividing by ε2\varepsilon^2ε2 proves the inequality.

Chebyshev’s inequality around the mean

Taking c=μ=E[X]c=\mu=\mathbb{E}[X]c=μ=E[X] gives

P(∣X−μ∣≥ε)≤Var⁡(X)ε2.\mathbb{P}(|X-\mu|\ge\varepsilon) \le \frac{\operatorname{Var}(X)}{\varepsilon^2}.P(∣X−μ∣≥ε)≤ε2Var(X)​.

If σ\sigmaσ is the standard deviation of XXX and ε=kσ\varepsilon=k\sigmaε=kσ for k>0k>0k>0, then

P(∣X−μ∣≥kσ)≤1k2.\mathbb{P}(|X-\mu|\ge k\sigma)\le\frac{1}{k^2}.P(∣X−μ∣≥kσ)≤k21​.

This is a distribution-free bound: it applies whenever the variance exists, without requiring a specific distributional shape.

Example: a uniform random variable

Suppose XXX is uniform on [0,1][0,1][0,1]. Then

μ=12,Var⁡(X)=σ2=112.\mu=\frac{1}{2}, \qquad \operatorname{Var}(X)=\sigma^2=\frac{1}{12}.μ=21​,Var(X)=σ2=121​.

For k=2k=2k=2, Chebyshev’s inequality gives

P(∣X−12∣≥212)≤14.\mathbb{P}\left(\left|X-\frac{1}{2}\right| \ge \frac{2}{\sqrt{12}}\right) \le \frac{1}{4}.P(​X−21​​≥12​2​)≤41​.

Since 212=13≈0.577\frac{2}{\sqrt{12}}=\frac{1}{\sqrt{3}}\approx 0.57712​2​=3​1​≈0.577, while any value in [0,1][0,1][0,1] is at most 12\frac{1}{2}21​ from its mean, the event is impossible. Its actual probability is 000. The bound 14\frac{1}{4}41​ is valid but not tight in this case.


Markov’s inequality

Let h(X)h(X)h(X) be a nonnegative function of a random variable XXX, and suppose its expectation exists. For ε>0\varepsilon>0ε>0,

P(h(X)≥ε)≤E[h(X)]ε.\mathbb{P}(h(X)\ge\varepsilon) \le \frac{\mathbb{E}[h(X)]}{\varepsilon}.P(h(X)≥ε)≤εE[h(X)]​.

Proof

Let AAA be the event {h(X)≥ε}\{h(X)\ge\varepsilon\}{h(X)≥ε}. Since h(X)≥0h(X)\ge 0h(X)≥0 everywhere, its expected value is at least its contribution on AAA. On AAA, h(X)≥εh(X)\ge\varepsilonh(X)≥ε, so

E[h(X)]≥ε P(A)=ε P(h(X)≥ε).\mathbb{E}[h(X)] \ge \varepsilon\,\mathbb{P}(A) =\varepsilon\,\mathbb{P}(h(X)\ge\varepsilon).E[h(X)]≥εP(A)=εP(h(X)≥ε).

Dividing by ε\varepsilonε gives Markov’s inequality.

Moment bound

For any r>0r>0r>0, choose h(X)=∣X∣rh(X)=|X|^rh(X)=∣X∣r and ε=kr\varepsilon=k^rε=kr, where k>0k>0k>0. If E[∣X∣r]\mathbb{E}[|X|^r]E[∣X∣r] exists, Markov’s inequality yields

P(∣X∣≥k)≤E[∣X∣r]kr.\mathbb{P}(|X|\ge k) \le \frac{\mathbb{E}[|X|^r]}{k^r}.P(∣X∣≥k)≤krE[∣X∣r]​.

This bounds the probability that ∣X∣|X|∣X∣ exceeds a threshold using its rrrth absolute moment.

Chebyshev’s inequality as a consequence of Markov’s inequality

Choose

h(X)=(X−μ)2,ε=k2σ2.h(X)=(X-\mu)^2, \qquad \varepsilon=k^2\sigma^2.h(X)=(X−μ)2,ε=k2σ2.

Then Markov’s inequality gives

P(∣X−μ∣≥kσ)=P((X−μ)2≥k2σ2)≤E[(X−μ)2]k2σ2=1k2.\begin{aligned} \mathbb{P}(|X-\mu|\ge k\sigma) &=\mathbb{P}\big((X-\mu)^2\ge k^2\sigma^2\big)\\ &\le \frac{\mathbb{E}[(X-\mu)^2]}{k^2\sigma^2}\\ &=\frac{1}{k^2}. \end{aligned}P(∣X−μ∣≥kσ)​=P((X−μ)2≥k2σ2)≤k2σ2E[(X−μ)2]​=k21​.​

Thus, Chebyshev’s inequality follows from Markov’s inequality by applying it to the squared deviation from the mean. Markov’s inequality is the more general result; Chebyshev’s inequality is a useful special case.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent