Skip to content
nonconvexcard

Expectation, Variance and Conditional Expectation

Expectation as an integral, the variance identities used in every bias–variance computation, and conditional expectation as an orthogonal projection.

ProbabilityCore⏱ 3 hours10 min readexpectationvariancecovarianceconditional expectationtower rule
4 problems →

Expectation

DefinitionExpectation

For a random variable X≥0X \ge 0, EX=∫ΩX dP∈[0,∞]\E X = \int_\Omega X \, d\P \in [0,\infty], defined as the supremum of the integrals of simple functions below XX. For general XX, write X=X+−X−X = X^+ - X^- and set EX=EX+−EX−\E X = \E X^+ - \E X^- whenever at least one term is finite; XX is integrable when E∣X∣<∞\E|X| < \infty.

Expectation is linear, monotone, and satisfies ∣EX∣≤E∣X∣|\E X| \le \E|X|. The following identity is the one that turns tail bounds into moment bounds and back, and it is used constantly on the sub-Gaussian page.

PropositionTail formula for the expectation

For X≥0X \ge 0,

EX=∫0∞P(X>t) dt,and more generallyE[Xp]=p∫0∞tp−1 P(X>t) dt(p>0).\E X = \int_0^\infty \P(X > t)\,dt, \qquad\text{and more generally}\qquad \E[X^p] = p\int_0^\infty t^{p-1}\,\P(X>t)\,dt \quad (p > 0).

Variance, covariance and the decompositions that matter

DefinitionVariance and covariance

For square-integrable X,YX, Y,

Var⁡(X)=E[(X−EX)2]=E[X2]−(EX)2,Cov⁡(X,Y)=E[(X−EX)(Y−EY)].\Var(X) = \E\big[(X - \E X)^2\big] = \E[X^2] - (\E X)^2, \qquad \Cov(X,Y) = \E\big[(X-\E X)(Y - \E Y)\big] .

For a random vector X∈RdX \in \R^d the covariance matrix is Σ=E[(X−EX)(X−EX)⊤]∈Sd\Sigma = \E[(X - \E X)(X-\E X)^\top] \in \mathbb{S}^d, and Σ⪰0\Sigma \succeq 0 because v⊤Σv=Var⁡(⟨v,X⟩)≥0v^\top \Sigma v = \Var(\ip{v}{X}) \ge 0.

PropositionBias–variance and variance decompositions

Let θ^\hat\theta be a square-integrable estimator of a constant θ\theta, and let G\mathcal{G} be a sub-σ\sigma-algebra. Then

E[(θ^−θ)2]⏟mean squared error=(Eθ^−θ)2⏟bias2+Var⁡(θ^)⏟variance,\underbrace{\E\big[(\hat\theta - \theta)^2\big]}_{\text{mean squared error}} = \underbrace{\big(\E\hat\theta - \theta\big)^2}_{\text{bias}^2} + \underbrace{\Var(\hat\theta)}_{\text{variance}},

and

Var⁡(X)=E[Var⁡(X∣G)]+Var⁡(E[X∣G])\Var(X) = \E\big[\Var(X \mid \mathcal{G})\big] + \Var\big(\E[X\mid\mathcal{G}]\big)

(the law of total variance).

Key idea

The bias–variance identity is exact algebra, not an approximation or a heuristic trade-off. What is heuristic is the claim that reducing one must increase the other; that claim is a description of certain model families, and the double descent page shows regimes where it plainly fails. Keep the identity and the folklore separate.

The vector version of the variance-of-a-sum computation is used in every mini-batch argument:

Var⁡(1n∑i=1nXi)=1n2∑i,jCov⁡(Xi,Xj)  =i.i.d.  σ2n.\Var\left(\frac1n\sum_{i=1}^n X_i\right) = \frac{1}{n^2}\sum_{i,j}\Cov(X_i,X_j) \;\overset{\text{i.i.d.}}{=}\; \frac{\sigma^2}{n} .

The middle expression is the honest one. The σ2/n\sigma^2/n rate is a consequence of independence, and correlated samples — adjacent tokens in a text corpus, say — do not enjoy it.

Conditional expectation

DefinitionConditional expectation

Let XX be integrable and G⊆A\mathcal{G} \subseteq \mathcal{A} a sub-σ\sigma-algebra. A random variable ZZ is a conditional expectation of XX given G\mathcal{G}, written Z=E[X∣G]Z = \E[X\mid\mathcal{G}], if

  1. ZZ is G\mathcal{G}-measurable, and
  2. E[Z1G]=E[X1G]\E[Z\one_G] = \E[X\one_G] for every G∈GG \in \mathcal{G}.

Such a ZZ exists and is unique up to almost-sure equality.

TheoremConditional expectation as an L2 projection

If E[X2]<∞\E[X^2] < \infty, then E[X∣G]\E[X\mid\mathcal{G}] is the orthogonal projection of XX onto the closed subspace L2(G)⊆L2(A)L^2(\mathcal{G}) \subseteq L^2(\mathcal{A}) of square-integrable G\mathcal{G}-measurable variables. Consequently

E[X∣G]=arg min⁡Z∈L2(G)E[(X−Z)2].\E[X \mid \mathcal{G}] = \argmin_{Z \in L^2(\mathcal{G})} \E\big[(X - Z)^2\big] .
PropositionTower property and pulling out what is known

Let X,YX, Y be integrable and H⊆G\mathcal{H} \subseteq \mathcal{G} sub-σ\sigma-algebras.

  1. Tower / smoothing. E[E[X∣G] ∣ H]=E[X∣H]\E\big[\E[X\mid\mathcal{G}]\ \big|\ \mathcal{H}\big] = \E[X\mid\mathcal{H}]; in particular E[E[X∣G]]=EX\E\big[\E[X\mid\mathcal{G}]\big] = \E X.
  2. Taking out what is known. If YY is G\mathcal{G}-measurable and XYXY is integrable, then E[XY∣G]=Y E[X∣G]\E[XY\mid\mathcal{G}] = Y\,\E[X\mid\mathcal{G}].
  3. Independence. If XX is independent of G\mathcal{G} then E[X∣G]=EX\E[X\mid\mathcal{G}] = \E X.

Problems

Moments from tail bounds via the layer-cake formulaProof · Intermediate · 30 min Law of total variance and its useProof · Intermediate · 30 min Conditional expectation minimises mean squared errorProof · Intermediate · 30 min The 1/n variance rate requires uncorrelated samplesNumerical · Intermediate · 30 min

References

  • BookRick Durrett (2019). Probability: Theory and Examples
  • BookDavid Williams (1991). Probability with MartingalesChapter 9 gives the conditional-expectation construction in the form used here.

These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.

Results stated on this page

Problems (4)

All problems

Papers that use this mathematics