Skip to content
GATEiit

GATE DA · Probability and Statistics

Conditional expectation and variance

Conditional expectation $E[X \mid Y]$ as a random variable, the law of total expectation, conditional variance and the law of total variance, and random sums; GATE asks two-stage numericals and property checks.

Before you start

This topic comes before: Bias–variance trade-off

Concept notes

1. Conditional expectation given an event or a value

For a discrete pair, the conditional PMF of X given Y=y is pX∣Y(x∣y)=p(x,y)pY(y). The conditional expectation is its mean: E[X∣Y=y]=∑xx pX∣Y(x∣y). For a continuous pair, use the conditional density fX∣Y(x∣y)=f(x,y)fY(y) and integrate: E[X∣Y=y]=∫x fX∣Y(x∣y) dx.

So E[X∣Y=y] is a number that depends on y, say g(y). Plugging in the random Y gives E[X∣Y]=g(Y), which is a random variable: it is a function of Y and takes the value g(y) with probability P(Y=y).

Example: (X,Y) uniform on the triangle 0<x<y<1 (density 2). Given Y=y, X is uniform on (0,y), so E[X∣Y=y]=y/2 and E[X∣Y]=Y/2.

2. Law of total expectation (tower rule)

Averaging the conditional means, weighted by how likely each condition is, recovers the overall mean: E[X]=E[E[X∣Y]]=∑yE[X∣Y=y] P(Y=y). This is the expectation version of the law of total probability. Use it for two-stage experiments: first something random picks a case, then X is drawn within that case.

Properties (all GATE favourites):

  • Linearity: E[aX+bZ∣Y]=aE[X∣Y]+bE[Z∣Y].
  • Taking out what is known: E[g(Y) X∣Y]=g(Y) E[X∣Y]; in particular E[g(Y)∣Y]=g(Y).
  • Independence: if X and Y are independent, E[X∣Y]=E[X], a constant.
  • Best predictor: among all functions h(Y), E[X∣Y] minimises the mean squared error E[(X−h(Y))2].

First-step analysis uses the tower rule with Y = the outcome of the first trial. For tosses until the first head with P(H)=p: E[N]=1+(1−p)E[N], so E[N]=1/p.

3. Conditional variance and the law of total variance

The conditional variance is the variance within one condition: Var(X∣Y=y)=E[X2∣Y=y]−(E[X∣Y=y])2. Like E[X∣Y], Var(X∣Y) is a random variable (a function of Y).

Law of total variance: Var(X)=E[Var(X∣Y)]+Var(E[X∣Y]).

  • The first term is the average spread within groups.
  • The second is the spread between group means.

Consequences: Var(X)≥E[Var(X∣Y)] and Var(X)≥Var(E[X∣Y]). The same split is behind ANOVA and the within-cluster / between-cluster decomposition used in clustering.

In the diagram, the within-group variances are 2/3 and 1, so E[Var(X∣Y)]=0.4(2/3)+0.6(1)=13/15; the group means 2 and 3 give Var(E[X∣Y])=0.4(4)+0.6(9)−2.62=0.24. Total Var(X)=13/15+6/25=83/75≈1.107.

Y = 0 (0.4)Y = 1 (0.6)12324E[X|Y=0] = 2E[X|Y=1] = 3E[X] = 2.6
Two groups with their conditional means (thick ticks) and the overall mean 2.6 (dashed): total spread = within-group spread + between-group spread

4. Random sums

A random sum S=X1+X2+⋯+XN adds a random number N of terms, where the Xi are independent and identically distributed (i.i.d.) with mean μ and variance σ2, and N is independent of them. Examples: total bill of a random number of customers, total size of a random number of packets.

Condition on N=n: E[S∣N=n]=nμ and Var(S∣N=n)=nσ2. The two laws then give E[S]=E[N] μ,Var(S)=E[N] σ2+Var(N) μ2.

The second term is easy to forget: even if every Xi were a constant μ, S=Nμ would still vary because N does.

When to use conditioning, in short: whenever the problem says "first …, then …", "a random number of …", or "depending on which …".

Formulas to remember

Conditional expectation (discrete)
E[X∣Y=y]=∑xx p(x,y)pY(y)
Conditional expectation (continuous)
E[X∣Y=y]=∫x f(x,y)fY(y) dx
Law of total expectation
E[X]=E[E[X∣Y]]
Conditional variance
Var(X∣Y)=E[X2∣Y]−(E[X∣Y])2
Law of total variance
Var(X)=E[Var(X∣Y)]+Var(E[X∣Y])
Taking out what is known
E[g(Y)X∣Y]=g(Y) E[X∣Y]
Random sum mean
E[∑i=1NXi]=E[N] μ
Random sum varianceXi i.i.d. with mean μ, variance σ2, independent of N
Var(∑i=1NXi)=E[N] σ2+Var(N) μ2

Common mistakes

  • Treating E[X∣Y] as a number; it is a random variable (a function of Y), and only E[X∣Y=y] is a number.
  • Using only E[Var(X∣Y)] for Var(X) and forgetting the between-group term Var(E[X∣Y]).
  • Writing Var(S)=E[N]σ2 for a random sum and dropping Var(N)μ2.
  • Averaging conditional means with equal weights instead of the probabilities P(Y=y).
  • Forgetting to divide by the marginal fY(y) when forming a conditional density.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Two-stage experiment: mean and variance

numerical

Y=0 with probability 0.4 and Y=1 with probability 0.6. Given Y=0, X is uniform on {1,2,3}; given Y=1, X is uniform on {2,4}. Find E[X] and Var(X).

  1. Step 1: Find the conditional means.

    Try it on paper first.

Example 2: Total bill of a random number of customers

numerical

The number of customers N in an hour has mean 4 and variance 2. Each customer spends an amount with mean Rs 50 and variance 100, independently of the others and of N. Find the mean and variance of the total spend.

  1. Step 1: Write the conditional mean and variance given $N = n$.

    Try it on paper first.

Example 3: First-step analysis: rolls until a six

numerical

A fair die is rolled until a six appears. Find the expected number of rolls.

  1. Step 1: Condition on the first roll.

    Try it on paper first.

Example 4: Continuous case on a triangle

numerical

(X,Y) has density f(x,y)=2 on 0<x<y<1. Find E[X∣Y=y] and use it to find E[X].

  1. Step 1: Find the marginal of $Y$.

    Try it on paper first.

Previous year questions

3 official GATE DA questions on this topic, newest first.

Practise these 3 PYQs →

Topic test

10 questions: up to 3 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.