Quant Sandbox
DerivativesPortfolio & RiskFixed IncomeCorporate FinanceProbability & MeasureStochastic ModelsMarket MicrostructureGuide
Guide
Derivatives pricing0 / 17
01Forwards, calls and puts02Combining positions03Arbitrage and the forward price04Put–call parity05The one-step binomial model06Risk-neutral probabilities07Multi-step trees and backward induction08American options and early exercise09Delta and hedging10Geometric Brownian motion11The Black–Scholes formula12The Greeks: gamma, vega, theta and rho13Options on dividend-paying stocks, indices, currencies and futures14Implied volatility and the volatility smile15Stochastic volatility and the Heston model16Static replication: Breeden–Litzenberger and Carr–Madan17Exotic options: barriers, Asians and digitals
Portfolio & risk0 / 12
01Returns and volatility02Diversification and correlation03The efficient frontier and the capital market line04Risk aversion and the optimal complete portfolio05CAPM, beta and the security market line06Performance measures: Sharpe, Treynor, Jensen and information ratio07Factor models and systematic risk08The Fama–French factor models09Value at Risk and expected shortfall10Systemic risk and contagion11Portfolio constraints and the no-short-sales frontier12Estimating expected returns and covariances
Fixed income0 / 10
01Bond prices and yields02Duration and convexity03Immunization and duration matching04Spot rates, forward rates and the yield curve05Non-parallel curve moves and key-rate durations06Bond futures and the cheapest-to-deliver07Interest rate swaps08Callable bonds and negative convexity09Credit risk: default probabilities and credit spreads10Real rates, inflation and inflation-linked bonds
Corporate finance0 / 10
01Interest, compounding and discounting02Annuities, perpetuities and loan amortization03Net present value and internal rate of return04Project risk: sensitivity, scenarios and Monte Carlo NPV05The weighted average cost of capital06Capital structure and the Modigliani–Miller theorems07Dividends, payout policy and the dividend discount model08Discounted cash flow valuation09Relative valuation with multiples10Real options: the value of flexibility
Probability and measure0 / 13
01Measuring the size of sets02σ-algebras and Borel sets03Lebesgue measure and null sets04Measurable functions05The Lebesgue integral06Convergence theorems07Probability spaces and Kolmogorov's axioms08Random variables and their distributions09Expectation, variance and inequalities10Independence and product measures11Modes of convergence and the law of large numbers12Conditional probability and conditional expectation13Measure theory in option pricing
Stochastic models0 / 17
01Random walks and Brownian motion02The law of large numbers and the central limit theorem03Probability spaces, σ-algebras and random variables04Filtrations, adapted processes and stopping times05Conditional expectation and martingales06Properties of Brownian motion07The reflection principle and first passage times08The Brownian bridge09The Itô integral10Itô's lemma11Kolmogorov equations and the Feynman–Kac formula12Change of measure and Girsanov's theorem13Monte Carlo option pricing14Simulating SDEs: the Euler–Maruyama scheme15Correlated Brownian motions and multi-asset models16Mean reversion: Ornstein–Uhlenbeck and Vasicek17Jumps and the Merton jump-diffusion model
Market microstructure0 / 11
01Market makers and liquidity02The limit order book03Queue position and fill probability04Adverse selection and informed trading05The Glosten–Milgrom model06Measuring and decomposing the bid–ask spread07Informed trading and Kyle's lambda08Price impact and optimal execution09Inventory risk and quote skewing10Optimal quoting: the Avellaneda–Stoikov model11Market making profit and loss attribution
Knowledge graph

© 2026 Quant Sandbox · A study aid for quantitative finance

Privacy & dataNo cookies

This site does not use cookies and asks for no personal data. It keeps a few small settings in your browser's local storage — your chosen theme and language, the sidebar layout, and your progress and answers in the Guides — so it remembers them on your next visit. This data never leaves your device; clearing your browser storage removes it. Inputs you change can also be captured in the page URL, so you can share or bookmark a specific setup. The site uses Vercel Web Analytics, a privacy-friendly, cookieless service that records only anonymous, aggregated usage (such as page views) without identifying you or tracking you across other sites.

Guides/Probability and measure/12

Conditional probability and conditional expectation

Lesson 12 of 13 · 1 min read

The lesson "Probability spaces and Kolmogorov's axioms" turned probability into a measure of total mass one on a space of outcomes, "Expectation, variance and inequalities" defined the expectation E[X]\mathbb{E}[X]E[X] as the integral of a random variable against that measure, and "Independence and product measures" introduced the conditional probability P(A∣B)\mathbb{P}(A \mid B)P(A∣B) in brief, as the tool that independence needed. All of these describe a state of knowledge in which nothing has been observed. This lesson asks what changes when part of the answer is revealed. It starts with conditioning on a single event, derives the multiplication rule and Bayes' rule, and then moves to the conditional expectation of a random variable given a partition and finally given a σ-algebra, which is the best prediction that the information at hand allows.

Conditional probability

Recall the two dice of "Independence and product measures", with outcomes (a,b)(a, b)(a,b), aaa on the first die and bbb on the second. A sum of 8 has probability 5/36≈0.13895/36 \approx 0.13895/36≈0.1389, and once you are told that the first die shows 3, only the six outcomes (3,1),…,(3,6)(3, 1), \ldots, (3, 6)(3,1),…,(3,6) remain, one of which, (3,5)(3, 5)(3,5), has sum 8, so the probability becomes 1/6≈0.16671/6 \approx 0.16671/6≈0.1667. This lesson starts again from that example and develops conditioning in full.

The recipe behind this calculation is to shrink the space of outcomes to the event that was observed, and then rescale so that the total probability is 1 again. For events AAA and BBB with P(B)>0\mathbb{P}(B) > 0P(B)>0, the conditional probability of AAA given BBB is

P(A∣B)=P(A∩B)P(B).\mathbb{P}(A \mid B) = \frac{\mathbb{P}(A \cap B)}{\mathbb{P}(B)}.P(A∣B)=P(B)P(A∩B)​.

In words: take the part of AAA that lies inside BBB and measure it against the size of BBB. The numerator discards everything outside BBB, and the division by P(B)\mathbb{P}(B)P(B) makes BBB itself have probability P(B∣B)=1\mathbb{P}(B \mid B) = 1P(B∣B)=1. In frequency terms: throw the dice many times, keep only the throws whose first die shows 3, and about 1/61/61/6 of those have sum 8.

As "Independence and product measures" noted, the new probability P(⋅∣B)\mathbb{P}(\cdot \mid B)P(⋅∣B) is itself a probability measure on the same events, and the check is short. Its values are non-negative, being ratios of non-negative numbers; it gives the sure event the value P(Ω∣B)=P(B)/P(B)=1\mathbb{P}(\Omega \mid B) = \mathbb{P}(B)/\mathbb{P}(B) = 1P(Ω∣B)=P(B)/P(B)=1; and for disjoint events A1,A2,…A_1, A_2, \ldotsA1​,A2​,… the pieces Ai∩BA_i \cap BAi​∩B are disjoint too, so countable additivity of P\mathbb{P}P gives

P(⋃iAi ∣ B)=P(⋃i(Ai∩B))P(B)=∑iP(Ai∩B)P(B)=∑iP(Ai∣B).\mathbb{P}\Big(\bigcup_i A_i \,\Big|\, B\Big) = \frac{\mathbb{P}\big(\bigcup_i (A_i \cap B)\big)}{\mathbb{P}(B)} = \sum_i \frac{\mathbb{P}(A_i \cap B)}{\mathbb{P}(B)} = \sum_i \mathbb{P}(A_i \mid B).P(i⋃​Ai​​B)=P(B)P(⋃i​(Ai​∩B))​=i∑​P(B)P(Ai​∩B)​=i∑​P(Ai​∣B).

Every rule derived from the axioms in "Probability spaces and Kolmogorov's axioms" therefore holds for conditional probabilities as well. For instance P(Ac∣B)=1−P(A∣B)\mathbb{P}(A^c \mid B) = 1 - \mathbb{P}(A \mid B)P(Ac∣B)=1−P(A∣B). Information can raise or lower a probability. The chance that the sum is at least 10 is 6/36=1/66/36 = 1/66/36=1/6. Given that the first die shows 6, three of the six possible outcomes reach it and the probability is 1/21/21/2; given that it shows 1, none does and the probability is 0.

Conditioning is not symmetric. Reverse the roles in the example above and ask for the probability that the first die shows 3 given that the sum is 8. Only five outcomes have sum 8, and exactly one of them has a 3 in front:

P(first=3∣sum=8)=1/365/36=15≠16=P(sum=8∣first=3).\mathbb{P}(\text{first} = 3 \mid \text{sum} = 8) = \frac{1/36}{5/36} = \frac15 \ne \frac16 = \mathbb{P}(\text{sum} = 8 \mid \text{first} = 3).P(first=3∣sum=8)=5/361/36​=51​=61​=P(sum=8∣first=3).

The numerators agree, since both describe the outcome (3,5)(3, 5)(3,5), but the denominators differ: one universe has six outcomes and the other five. Confusing the two conditional probabilities is the most common mistake in the subject, and the section on Bayes' rule shows how costly it can be.

The formula needs P(B)>0\mathbb{P}(B) > 0P(B)>0; otherwise it reads 0/00/00/0. This is more than a technicality: a number drawn uniformly from [0,1][0, 1][0,1] equals any given value with probability zero, yet conditioning on information about it can make sense. The section on σ-algebras defines conditioning without dividing by the probability of the observation.

The multiplication rule and total probability

Multiplying the definition by P(B)\mathbb{P}(B)P(B) gives the multiplication rule:

P(A∩B)=P(B) P(A∣B).\mathbb{P}(A \cap B) = \mathbb{P}(B)\,\mathbb{P}(A \mid B).P(A∩B)=P(B)P(A∣B).

In words: the chance that both events happen is the chance that the first happens, times the chance that the second happens once the first has. Applying the rule twice extends it to chains,

P(A1∩A2∩A3)=P(A1) P(A2∣A1) P(A3∣A1∩A2).\mathbb{P}(A_1 \cap A_2 \cap A_3) = \mathbb{P}(A_1)\,\mathbb{P}(A_2 \mid A_1)\,\mathbb{P}(A_3 \mid A_1 \cap A_2).P(A1​∩A2​∩A3​)=P(A1​)P(A2​∣A1​)P(A3​∣A1​∩A2​).

Take an urn with 3 red and 2 blue balls and draw three balls without putting any back. The first is red with probability 3/53/53/5. Given that, 2 red balls remain among 4, so the second is red with probability 2/42/42/4; given both, 1 red ball remains among 3. The chance that all three are red is 35⋅24⋅13=110\tfrac35 \cdot \tfrac24 \cdot \tfrac13 = \tfrac1{10}53​⋅42​⋅31​=101​, which agrees with counting: one of the 10 equally likely sets of three balls consists of the three red ones.

The second rule splits a probability into cases. A partition of Ω\OmegaΩ is a list of disjoint events B1,…,BmB_1, \ldots, B_mB1​,…,Bm​ of positive probability that together cover Ω\OmegaΩ, as in "σ-algebras and Borel sets". Any event AAA falls apart into the disjoint pieces A∩B1,…,A∩BmA \cap B_1, \ldots, A \cap B_mA∩B1​,…,A∩Bm​, and adding their probabilities, each written with the multiplication rule, gives the law of total probability:

P(A)=∑i=1mP(A∩Bi)=∑i=1mP(Bi) P(A∣Bi).\mathbb{P}(A) = \sum_{i=1}^{m} \mathbb{P}(A \cap B_i) = \sum_{i=1}^{m} \mathbb{P}(B_i)\,\mathbb{P}(A \mid B_i).P(A)=i=1∑m​P(A∩Bi​)=i=1∑m​P(Bi​)P(A∣Bi​).

In words: the probability of AAA is a weighted average of its probabilities in the separate cases, and the weights are the probabilities of the cases. Split the two dice by the value of the first die. Each case has probability 1/61/61/6. Given first =1= 1=1, a sum of 8 is impossible; given first =2,…,6= 2, \ldots, 6=2,…,6 the second die must show one particular number, so the conditional probability is 1/61/61/6. Then

P(sum=8)=16(0+5⋅16)=536,\mathbb{P}(\text{sum} = 8) = \tfrac16\big(0 + 5 \cdot \tfrac16\big) = \tfrac5{36},P(sum=8)=61​(0+5⋅61​)=365​,

as it should be. A second example: in the same urn, with nothing known about the first draw, the second ball is red with probability 35⋅24+25⋅34=35\tfrac35 \cdot \tfrac24 + \tfrac25 \cdot \tfrac34 = \tfrac3553​⋅42​+52​⋅43​=53​, exactly the probability that the first ball is red. The idea of weighting case-by-case answers by the probabilities of the cases returns below, with expectations in place of probabilities.

Bayes' rule

The multiplication rule can be applied in two orders, P(A∩B)=P(A∣B) P(B)=P(B∣A) P(A)\mathbb{P}(A \cap B) = \mathbb{P}(A \mid B)\,\mathbb{P}(B) = \mathbb{P}(B \mid A)\,\mathbb{P}(A)P(A∩B)=P(A∣B)P(B)=P(B∣A)P(A). Dividing by P(A)\mathbb{P}(A)P(A) turns one conditional probability into the other. This is Bayes' rule:

P(B∣A)=P(A∣B) P(B)P(A).\mathbb{P}(B \mid A) = \frac{\mathbb{P}(A \mid B)\,\mathbb{P}(B)}{\mathbb{P}(A)}.P(B∣A)=P(A)P(A∣B)P(B)​.

The denominator can be expanded with the law of total probability. The reading is a change of beliefs: P(B)\mathbb{P}(B)P(B) is the prior, the probability of BBB before anything is observed, and P(B∣A)\mathbb{P}(B \mid A)P(B∣A) is the posterior, its probability after AAA has been observed.

Here is the standard example. A disease affects 1% of a population, so the prevalence is 0.010.010.01. A test comes out positive for 99% of the ill people, a figure called the sensitivity, P(positive∣ill)=0.99\mathbb{P}(\text{positive} \mid \text{ill}) = 0.99P(positive∣ill)=0.99. It comes out negative for 95% of the healthy people, called the specificity, P(negative∣healthy)=0.95\mathbb{P}(\text{negative} \mid \text{healthy}) = 0.95P(negative∣healthy)=0.95, so it is positive for the other 5% of the healthy. A randomly chosen person tests positive. How likely is it that this person is ill? Many people answer something close to 99%. The multiplication rule gives the two ways of being positive:

P(ill∩pos)=0.01⋅0.99=0.0099,P(healthy∩pos)=0.99⋅0.05=0.0495.\mathbb{P}(\text{ill} \cap \text{pos}) = 0.01 \cdot 0.99 = 0.0099, \qquad \mathbb{P}(\text{healthy} \cap \text{pos}) = 0.99 \cdot 0.05 = 0.0495.P(ill∩pos)=0.01⋅0.99=0.0099,P(healthy∩pos)=0.99⋅0.05=0.0495.

Their sum is P(pos)=0.0594\mathbb{P}(\text{pos}) = 0.0594P(pos)=0.0594, by the law of total probability, and Bayes' rule gives

P(ill∣pos)=0.00990.0594=16≈0.1667.\mathbb{P}(\text{ill} \mid \text{pos}) = \frac{0.0099}{0.0594} = \frac16 \approx 0.1667.P(ill∣pos)=0.05940.0099​=61​≈0.1667.

The same calculation with people instead of probabilities makes the result easier to believe. Take 10,000 people. Of them 100 are ill and 99 of those test positive. The other 9,900 are healthy and 5% of them, 495 people, test positive too. In total 594 people are positive, and only 99 of them are ill: 99/594=1/699/594 = 1/699/594=1/6.

The intuition fails because of the base rate. The sensitivity answers P(positive∣ill)\mathbb{P}(\text{positive} \mid \text{ill})P(positive∣ill), but the question asked was the reverse, P(ill∣positive)\mathbb{P}(\text{ill} \mid \text{positive})P(ill∣positive), and these are different numbers. Few people are ill, so even a small false-alarm rate, applied to the many healthy people, produces more false alarms (495) than true detections (99). A strong test lifts a probability of 1% to 16.7%, not to 99%.

Posteriors can be updated again: if the person takes a second test and it is also positive, the posterior of the first test becomes the prior of the second. The two results are taken to be independent once the person's true health state is fixed. The worked example carries out both steps.

Worked example

A positive medical test

  1. Ill and positive: the prevalence times the sensitivity.

    0.01⋅0.99\displaystyle 0.01 \cdot 0.990.01⋅0.99=0.0099
  2. Healthy and positive: the share of healthy people times the false-alarm rate.

    0.99⋅0.05\displaystyle 0.99 \cdot 0.050.99⋅0.05=0.0495
  3. Positive in total, by the law of total probability:

    0.0099+0.0495\displaystyle 0.0099 + 0.04950.0099+0.0495=0.0594
  4. Bayes' rule: the probability of being ill after one positive test.

    0.0099/0.0594\displaystyle 0.0099 / 0.05940.0099/0.0594=0.1667
  5. A second, independent positive test; ill and positive again, starting from the new prior 0.16670.16670.1667.

    0.1667⋅0.99\displaystyle 0.1667 \cdot 0.990.1667⋅0.99=0.165
  6. Healthy and positive again:

    0.8333⋅0.05\displaystyle 0.8333 \cdot 0.050.8333⋅0.05=0.04167
  7. The probability of being ill after two positive tests:

    0.165/(0.165+0.04167)\displaystyle 0.165 / (0.165 + 0.04167)0.165/(0.165+0.04167)=0.7984

Conditional expectation given an event

The conditional measure P(⋅∣B)\mathbb{P}(\cdot \mid B)P(⋅∣B) is a probability measure, so it has expectations like any other. The conditional expectation of a random variable XXX given an event BBB with P(B)>0\mathbb{P}(B) > 0P(B)>0 is the expectation of XXX computed under P(⋅∣B)\mathbb{P}(\cdot \mid B)P(⋅∣B):

E[X∣B]=E[X 1B]P(B)=1P(B)∫BX dP.\mathbb{E}[X \mid B] = \frac{\mathbb{E}[X\,\mathbf{1}_B]}{\mathbb{P}(B)} = \frac{1}{\mathbb{P}(B)} \int_B X \, d\mathbb{P}.E[X∣B]=P(B)E[X1B​]​=P(B)1​∫B​XdP.

In words: average XXX over BBB only, with the weights given by P\mathbb{P}P, and rescale by the size of BBB. The indicator 1B\mathbf{1}_B1B​ switches XXX off outside BBB, so the numerator is the integral of XXX over BBB, and the denominator turns it into an average.

Let XXX be the face of one die and BBB the event that the face is even. Then E[X 1B]=(2+4+6)/6=2\mathbb{E}[X\,\mathbf{1}_B] = (2 + 4 + 6)/6 = 2E[X1B​]=(2+4+6)/6=2, P(B)=1/2\mathbb{P}(B) = 1/2P(B)=1/2, and E[X∣B]=2/(1/2)=4\mathbb{E}[X \mid B] = 2 / (1/2) = 4E[X∣B]=2/(1/2)=4, which is simply the average of the three equally likely faces 2, 4 and 6. For the odd faces the same computation gives 3. With two dice, E[first∣sum=8]=(2+3+4+5+6)/5=4\mathbb{E}[\text{first} \mid \text{sum} = 8] = (2 + 3 + 4 + 5 + 6)/5 = 4E[first∣sum=8]=(2+3+4+5+6)/5=4, because the five outcomes with sum 8 are equally likely. Without information the first die averages 3.53.53.5, so learning that the sum is 8, above the typical 7, moves the best guess up to 444. For a fixed event E[X∣B]\mathbb{E}[X \mid B]E[X∣B] is a single number; the next section lets the event depend on the outcome.

Conditional expectation given a partition

Imagine an observer who does not see the outcome ω\omegaω but is told which block of a partition B1,…,BmB_1, \ldots, B_mB1​,…,Bm​ it lies in. "σ-algebras and Borel sets" described such an observer by the σ-algebra G\mathcal{G}G of all unions of blocks, whose atoms are the blocks themselves. What should this observer predict for a random variable XXX? Inside block BiB_iBi​ the natural prediction is E[X∣Bi]\mathbb{E}[X \mid B_i]E[X∣Bi​]. This prediction depends on ω\omegaω only through the block, so it is a random variable, called the conditional expectation of $X$ given $\mathcal{G}$:

E[X∣G](ω)=∑i=1mE[X∣Bi] 1Bi(ω).\mathbb{E}[X \mid \mathcal{G}](\omega) = \sum_{i=1}^{m} \mathbb{E}[X \mid B_i]\,\mathbf{1}_{B_i}(\omega).E[X∣G](ω)=i=1∑m​E[X∣Bi​]1Bi​​(ω).

In words: flatten XXX on every block to its average over that block. The result is constant on each atom of G\mathcal{G}G, and by "Measurable functions" that is exactly what it means for a function to be measurable with respect to a σ-algebra generated by a partition. So E[X∣G]\mathbb{E}[X \mid \mathcal{G}]E[X∣G] is G\mathcal{G}G-measurable: it uses no information beyond the blocks.

Take the face XXX of a die with four different observers. One sees only the parity, with blocks {1,3,5}\{1, 3, 5\}{1,3,5} and {2,4,6}\{2, 4, 6\}{2,4,6}, and predicts 333 on the first and 444 on the second. One sees only whether the face is at most 2, with blocks {1,2}\{1, 2\}{1,2} and {3,4,5,6}\{3, 4, 5, 6\}{3,4,5,6}, and predicts 1.51.51.5 and 4.54.54.5. One sees nothing, so the only block is Ω\OmegaΩ and the prediction is the constant 3.53.53.5. One sees the face itself, all six blocks are single points, and the prediction is XXX. The more the observer knows, the closer the prediction follows XXX.

For a larger example, let G\mathcal{G}G be generated by the sum of the two dice, which has 11 possible values and so 11 blocks. By symmetry, E[first∣sum]=sum/2\mathbb{E}[\text{first} \mid \text{sum}] = \text{sum}/2E[first∣sum]=sum/2: the outcomes (a,b)(a, b)(a,b) and (b,a)(b, a)(b,a) have the same sum and are equally likely, so within every block the two dice have the same average, and these two averages add up to the sum. For sum 7 the block has six outcomes and the average is 3.53.53.5; for sum 8 it is 444, for sum 12 it is 666, and for sum 2 it is 111.

The block averages, weighted by the probabilities of the blocks, add up to the plain expectation. This is the law of total expectation:

E[E[X∣G]]=∑i=1mE[X∣Bi] P(Bi)=∑i=1mE[X 1Bi]=E[X].\mathbb{E}\big[\mathbb{E}[X \mid \mathcal{G}]\big] = \sum_{i=1}^{m} \mathbb{E}[X \mid B_i]\,\mathbb{P}(B_i) = \sum_{i=1}^{m} \mathbb{E}[X\,\mathbf{1}_{B_i}] = \mathbb{E}[X].E[E[X∣G]]=i=1∑m​E[X∣Bi​]P(Bi​)=i=1∑m​E[X1Bi​​]=E[X].

The first equality weights each block average by its probability, the second uses the definition of E[X∣Bi]\mathbb{E}[X \mid B_i]E[X∣Bi​], and the third adds up the pieces of XXX. The parity observer gives 12⋅3+12⋅4=3.5\tfrac12 \cdot 3 + \tfrac12 \cdot 4 = 3.521​⋅3+21​⋅4=3.5, the "at most 2" observer 13⋅1.5+23⋅4.5=3.5\tfrac13 \cdot 1.5 + \tfrac23 \cdot 4.5 = 3.531​⋅1.5+32​⋅4.5=3.5, and the dice-sum observer ∑sP(sum=s) s/2=126/36=3.5\sum_s \mathbb{P}(\text{sum} = s)\, s/2 = 126/36 = 3.5∑s​P(sum=s)s/2=126/36=3.5: each time the expectation of one die.

Worked example

Two dice given their sum

  1. The five outcomes with sum 8 have first dice 2, 3, 4, 5, 6, so the block average is:

    (2+3+4+5+6)/5\displaystyle (2 + 3 + 4 + 5 + 6)/5(2+3+4+5+6)/5=4
  2. Sum 3 has two outcomes, (1,2)(1, 2)(1,2) and (2,1)(2, 1)(2,1):

    (1+2)/2\displaystyle (1 + 2)/2(1+2)/2=1.5
  3. Sum 7 has six outcomes, with first dice 1 to 6:

    (1+2+3+4+5+6)/6\displaystyle (1 + 2 + 3 + 4 + 5 + 6)/6(1+2+3+4+5+6)/6=3.5
  4. The block with sum 8 has probability:

    5/36\displaystyle 5/365/36=0.1389
  5. Weight every block average s/2s/2s/2 by the number of outcomes nsn_sns​ with sum sss (1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1), and divide by 36:

    136∑sns⋅s2=12636\displaystyle \tfrac{1}{36} \sum_s n_s \cdot \tfrac{s}{2} = \tfrac{126}{36}361​s∑​ns​⋅2s​=36126​=3.5
  6. This is the expectation of the first die, as the law of total expectation says:

    (1+2+3+4+5+6)/6\displaystyle (1 + 2 + 3 + 4 + 5 + 6)/6(1+2+3+4+5+6)/6=3.5

Conditional expectation given a σ-algebra

Partitions are not enough. Let ω\omegaω be uniform on [0,1][0, 1][0,1] and let D=∣ω−12∣D = |\omega - \tfrac12|D=∣ω−21​∣ be its distance from the middle. An observer who is told D=dD = dD=d knows that ω\omegaω is one of the two points 12−d\tfrac12 - d21​−d and 12+d\tfrac12 + d21​+d, but each event {D=d}\{D = d\}{D=d} has probability zero, so E[X∣B]=E[X 1B]/P(B)\mathbb{E}[X \mid B] = \mathbb{E}[X\,\mathbf{1}_B]/\mathbb{P}(B)E[X∣B]=E[X1B​]/P(B) reads 0/00/00/0. Still, "what is the average of ω2\omega^2ω2 given D=dD = dD=d?" has an obvious answer: the two points are equally likely, so it is 12((12−d)2+(12+d)2)=14+d2\tfrac12\big((\tfrac12 - d)^2 + (\tfrac12 + d)^2\big) = \tfrac14 + d^221​((21​−d)2+(21​+d)2)=41​+d2, which is 0.260.260.26 for d=0.1d = 0.1d=0.1 and 0.31250.31250.3125 for d=0.25d = 0.25d=0.25. A definition is needed that produces such answers without dividing by a zero probability. The way out is to say what the answer must satisfy, instead of how to compute it.

Let XXX be an integrable random variable and let G⊆F\mathcal{G} \subseteq \mathcal{F}G⊆F be a sub-σ-algebra, the events the observer can decide. The conditional expectation E[X∣G]\mathbb{E}[X \mid \mathcal{G}]E[X∣G] is a random variable ZZZ with two properties:

(i) Z is G-measurable,(ii) ∫GZ dP=∫GX dP  for every G∈G.(\text{i})\ Z \text{ is } \mathcal{G}\text{-measurable}, \qquad (\text{ii})\ \int_G Z \, d\mathbb{P} = \int_G X \, d\mathbb{P} \ \text{ for every } G \in \mathcal{G}.(i) Z is G-measurable,(ii) ∫G​ZdP=∫G​XdP  for every G∈G.

Property (i) says that ZZZ is built from the observer's information alone: every question about ZZZ, such as "is ZZZ at most 0.3?", is one that G\mathcal{G}G can answer. Property (ii) says that on every event the observer can name, ZZZ has the same total as XXX, so ZZZ carries no bias. It is XXX with all the detail that G\mathcal{G}G cannot see averaged away.

Block averages satisfy both properties. A block average is constant on each block, which is (i). For G=BjG = B_jG=Bj​, ∫BjZ dP=E[X∣Bj] P(Bj)=E[X 1Bj]=∫BjX dP\int_{B_j} Z \, d\mathbb{P} = \mathbb{E}[X \mid B_j]\,\mathbb{P}(B_j) = \mathbb{E}[X\,\mathbf{1}_{B_j}] = \int_{B_j} X \, d\mathbb{P}∫Bj​​ZdP=E[X∣Bj​]P(Bj​)=E[X1Bj​​]=∫Bj​​XdP, and every other G∈GG \in \mathcal{G}G∈G is a union of blocks, over which both sides add up. The distance example passes as well. Take G={D≤0.1}=[0.4,0.6]G = \{D \le 0.1\} = [0.4, 0.6]G={D≤0.1}=[0.4,0.6], which has probability 0.20.20.2. On one side ∫Gω2 dω=(0.63−0.43)/3≈0.050667\int_G \omega^2 \, d\omega = (0.6^3 - 0.4^3)/3 \approx 0.050667∫G​ω2dω=(0.63−0.43)/3≈0.050667. On the other, Z=14+D2Z = \tfrac14 + D^2Z=41​+D2 and DDD has density 2 on [0,12][0, \tfrac12][0,21​], so ∫GZ dP=0.25⋅0.2+∫00.12d2 dd≈0.05+0.000667=0.050667\int_G Z \, d\mathbb{P} = 0.25 \cdot 0.2 + \int_0^{0.1} 2d^2 \, dd \approx 0.05 + 0.000667 = 0.050667∫G​ZdP=0.25⋅0.2+∫00.1​2d2dd≈0.05+0.000667=0.050667.

Is there such a ZZZ, and is it the only one? Uniqueness has a short proof. Suppose ZZZ and Z′Z'Z′ both satisfy (i) and (ii). The event G={Z>Z′}G = \{Z > Z'\}G={Z>Z′} belongs to G\mathcal{G}G, and by (ii) ∫G(Z−Z′) dP=0\int_G (Z - Z') \, d\mathbb{P} = 0∫G​(Z−Z′)dP=0. The integrand is positive on GGG, so GGG is a null set; the same holds for {Z<Z′}\{Z < Z'\}{Z<Z′}, hence Z=Z′Z = Z'Z=Z′ almost surely. Conditional expectation is determined up to a null set, and equalities between conditional expectations are always meant almost surely. Existence for every integrable XXX is the Radon–Nikodym theorem, which a later lesson of this track states. For a partition, the explicit formula above provides it.

The most common case is conditioning on a random variable YYY. Then E[X∣Y]\mathbb{E}[X \mid Y]E[X∣Y] means E[X∣σ(Y)]\mathbb{E}[X \mid \sigma(Y)]E[X∣σ(Y)], where σ(Y)\sigma(Y)σ(Y) is the σ-algebra of the events {Y∈B}\{Y \in B\}{Y∈B} from "Measurable functions". A σ(Y)\sigma(Y)σ(Y)-measurable random variable is a function of YYY, so E[X∣Y]=g(Y)\mathbb{E}[X \mid Y] = g(Y)E[X∣Y]=g(Y) for some function ggg, and the value g(y)g(y)g(y) is what one calls E[X∣Y=y]\mathbb{E}[X \mid Y = y]E[X∣Y=y]. For the dice, g(s)=s/2g(s) = s/2g(s)=s/2; for the distance example, g(d)=14+d2g(d) = \tfrac14 + d^2g(d)=41​+d2.

A conditional expectation E[X∣G]\mathbb{E}[X \mid \mathcal{G}]E[X∣G] is a random variable, not a number: it takes a value for each ω\omegaω, namely the best answer given what G\mathcal{G}G has revealed about ω\omegaω. Only E[X∣B]\mathbb{E}[X \mid B]E[X∣B], for a fixed event, is a number.

A concrete σ-algebra comes from the coin model of "Probability spaces and Kolmogorov's axioms", where a uniform ω∈[0,1]\omega \in [0, 1]ω∈[0,1] is read as an infinite sequence of fair coin tosses, its binary digits. Knowing the first kkk tosses means knowing which of the 2k2^k2k dyadic blocks [j/2k,(j+1)/2k)[j/2^k, (j+1)/2^k)[j/2k,(j+1)/2k) contains ω\omegaω, and the σ-algebra Gk\mathcal{G}_kGk​ generated by these blocks is the observer after kkk tosses. For X=ω2X = \omega^2X=ω2 and k=2k = 2k=2 the blocks are the four quarters of [0,1][0, 1][0,1], and the block averages are 148,748,1948,3748\tfrac1{48}, \tfrac7{48}, \tfrac{19}{48}, \tfrac{37}{48}481​,487​,4819​,4837​, that is 0.02080.02080.0208, 0.14580.14580.1458, 0.39580.39580.3958 and 0.77080.77080.7708. Their average is 13=E[ω2]\tfrac13 = \mathbb{E}[\omega^2]31​=E[ω2]. With no tosses known the prediction is the constant 13\tfrac1331​; after one toss it is 112≈0.0833\tfrac1{12} \approx 0.0833121​≈0.0833 on the left half and 712≈0.5833\tfrac7{12} \approx 0.5833127​≈0.5833 on the right half.

The figure shows this staircase. Choose a variable XXX, move the slider kkk from 0 to 4 and watch: at k=0k = 0k=0 the staircase is one flat line at E[X]\mathbb{E}[X]E[X], and every extra toss splits each block in two, so that it follows XXX more closely. The first readout does not change with kkk, because the block averages always average to E[X]\mathbb{E}[X]E[X]. At the defaults, X=ω2X = \omega^2X=ω2 and k=2k = 2k=2, there are four blocks, E[X]=0.3333\mathbb{E}[X] = 0.3333E[X]=0.3333, and the error readout shows 0.0068580.0068580.006858, which the next section explains. Switch on the comparison guess to see a second staircase.

Conditional expectation as block averagesOpen in Conditional Expectation
2
04
000.50.511
Mean of X
0.3333
Blocks
4
Error of 𝔼[X | 𝒢]
0.006858
Error of the guess
–

Raise k to reveal more tosses: each block splits in two and the staircase of block averages follows X more closely. With the guess on, the dashed staircase shows X at the midpoint of each block, and its error is never smaller.

Best prediction

Why average within a block, and not take another value? Because the average is the best prediction in a precise sense. Suppose the observer must predict XXX with a G\mathcal{G}G-measurable random variable ZZZ with E[Z2]<∞\mathbb{E}[Z^2] < \inftyE[Z2]<∞, and measure its quality by the mean squared error E[(X−Z)2]\mathbb{E}[(X - Z)^2]E[(X−Z)2]. Without information ZZZ must be a constant, the best constant is E[X]\mathbb{E}[X]E[X], and the error is the variance of XXX from "Expectation, variance and inequalities". The claim is that with information, M=E[X∣G]M = \mathbb{E}[X \mid \mathcal{G}]M=E[X∣G] is the best of all.

The proof has two steps. First, X−MX - MX−M is orthogonal to everything the observer can build: E[(X−M) Z]=0\mathbb{E}[(X - M)\,Z] = 0E[(X−M)Z]=0 for every G\mathcal{G}G-measurable ZZZ with finite second moment. For Z=1GZ = \mathbf{1}_GZ=1G​ with G∈GG \in \mathcal{G}G∈G this is exactly property (ii), because E[(X−M) 1G]=∫GX dP−∫GM dP=0\mathbb{E}[(X - M)\,\mathbf{1}_G] = \int_G X \, d\mathbb{P} - \int_G M \, d\mathbb{P} = 0E[(X−M)1G​]=∫G​XdP−∫G​MdP=0. Linearity extends it to finite sums ∑ai1Gi\sum a_i \mathbf{1}_{G_i}∑ai​1Gi​​, and a general ZZZ is a limit of such sums (an idea, not a complete proof). Second, write X−Z=(X−M)+(M−Z)X - Z = (X - M) + (M - Z)X−Z=(X−M)+(M−Z). The difference M−ZM - ZM−Z is G\mathcal{G}G-measurable, so the cross term vanishes by orthogonality, and the squares add:

E[(X−Z)2]=E[(X−M)2]+E[(M−Z)2].\mathbb{E}[(X - Z)^2] = \mathbb{E}[(X - M)^2] + \mathbb{E}[(M - Z)^2].E[(X−Z)2]=E[(X−M)2]+E[(M−Z)2].

The second term is never negative, and it is zero only if Z=MZ = MZ=M almost surely. So MMM is the best prediction, and every other prediction is worse by exactly the squared distance to MMM. This is Pythagoras' theorem for random variables: X−MX - MX−M is perpendicular to everything G\mathcal{G}G can build.

The figure's numbers illustrate it. For X=ω2X = \omega^2X=ω2 and four blocks, the best staircase has error 0.0068580.0068580.006858. Take instead the guess that evaluates XXX at the midpoint of each block, with values 164,964,2564,4964\tfrac1{64}, \tfrac9{64}, \tfrac{25}{64}, \tfrac{49}{64}641​,649​,6425​,6449​. Each differs from the block average by 1/192=0.0052081/192 = 0.0052081/192=0.005208, so the extra error is 0.0052082=0.00002710.005208^2 = 0.00002710.0052082=0.0000271 and the guess has error 0.0068850.0068850.006885, which is what the figure shows when the comparison guess is on. The guess is good, since squares are nearly linear on short blocks, but it cannot beat the block average.

More information can only help. If G⊆H\mathcal{G} \subseteq \mathcal{H}G⊆H, every G\mathcal{G}G-measurable prediction is also H\mathcal{H}H-measurable, so the minimum over the larger class is at most the minimum over the smaller one. For X=ω2X = \omega^2X=ω2 the error is 0.08890.08890.0889 with 1 block (no tosses known), then 0.02640.02640.0264, 0.00690.00690.0069 and 0.00170.00170.0017 with 2, 4 and 8 blocks. Each extra toss cuts the error by a factor of 3.4, 3.8 and then 4.0. Applying the Pythagoras identity to the constant prediction Z=E[X]Z = \mathbb{E}[X]Z=E[X] also splits the variance in two parts:

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

The first part is what the information leaves unexplained, the second is what it explains. With four blocks, 0.0889=0.0069+0.08200.0889 = 0.0069 + 0.08200.0889=0.0069+0.0820: the first two tosses explain about 92% of the variance of ω2\omega^2ω2.

Rules of conditional expectation

All the rules below follow from the two defining properties and have a simple block picture. They hold almost surely, since a conditional expectation is determined only up to a null set.

Linearity. E[aX+bY∣G]=a E[X∣G]+b E[Y∣G]\mathbb{E}[aX + bY \mid \mathcal{G}] = a\,\mathbb{E}[X \mid \mathcal{G}] + b\,\mathbb{E}[Y \mid \mathcal{G}]E[aX+bY∣G]=aE[X∣G]+bE[Y∣G]. Averaging over a block is a linear operation. For two dice, E[first+second∣sum]=sum\mathbb{E}[\text{first} + \text{second} \mid \text{sum}] = \text{sum}E[first+second∣sum]=sum, which is sum/2+sum/2\text{sum}/2 + \text{sum}/2sum/2+sum/2. Monotonicity goes with it: if X≤YX \le YX≤Y then E[X∣G]≤E[Y∣G]\mathbb{E}[X \mid \mathcal{G}] \le \mathbb{E}[Y \mid \mathcal{G}]E[X∣G]≤E[Y∣G], because averaging preserves order.

Taking out what is known. If ZZZ is G\mathcal{G}G-measurable, then

E[ZX∣G]=Z E[X∣G].\mathbb{E}[Z X \mid \mathcal{G}] = Z\,\mathbb{E}[X \mid \mathcal{G}].E[ZX∣G]=ZE[X∣G].

Inside a block, ZZZ is a constant, and a constant factors out of an average. For two dice, Z=sumZ = \text{sum}Z=sum is known once the sum is given, so E[first⋅sum∣sum]=sum2/2\mathbb{E}[\text{first} \cdot \text{sum} \mid \text{sum}] = \text{sum}^2/2E[first⋅sum∣sum]=sum2/2; given sum 8 the value is 323232, which is 888 times the block average 444. With X=1X = 1X=1 the rule gives E[Z∣G]=Z\mathbb{E}[Z \mid \mathcal{G}] = ZE[Z∣G]=Z: what the observer knows does not need predicting.

The tower property. If G⊆H\mathcal{G} \subseteq \mathcal{H}G⊆H, then

E[E[X∣H] ∣ G]=E[X∣G].\mathbb{E}\big[\mathbb{E}[X \mid \mathcal{H}] \,\big|\, \mathcal{G}\big] = \mathbb{E}[X \mid \mathcal{G}].E[E[X∣H]​G]=E[X∣G].

In words: predicting from the finer information and then forgetting the details down to G\mathcal{G}G is the same as predicting from G\mathcal{G}G directly, so the coarser information wins. Each coarse block is a union of fine blocks, and its average is the probability-weighted average of their averages. For X=ω2X = \omega^2X=ω2, going from four blocks to two: the left half has fine averages 148\tfrac1{48}481​ and 748\tfrac7{48}487​, with mean 112\tfrac1{12}121​, and the right half has 1948\tfrac{19}{48}4819​ and 3748\tfrac{37}{48}4837​, with mean 712\tfrac7{12}127​, exactly the two-block averages found above. The trivial σ-algebra for G\mathcal{G}G gives the law of total expectation.

Independence. If XXX is independent of G\mathcal{G}G, in the sense of "Independence and product measures", then E[X∣G]=E[X]\mathbb{E}[X \mid \mathcal{G}] = \mathbb{E}[X]E[X∣G]=E[X]: information that has nothing to do with XXX leaves the prediction unchanged. For two dice, E[second∣first]=3.5\mathbb{E}[\text{second} \mid \text{first}] = 3.5E[second∣first]=3.5. The figure shows a more surprising case. The values of X=4ω(1−ω)X = 4\omega(1 - \omega)X=4ω(1−ω) at mirror points ω\omegaω and 1−ω1 - \omega1−ω agree, so the two halves of [0,1][0, 1][0,1] look alike and the first toss says nothing about XXX. Choose this XXX and set k=1k = 1k=1: both block averages equal 2/32/32/3, and the error stays at its no-information value 0.08890.08890.0889.

Conditional Jensen. If φ\varphiφ is convex, then E[φ(X)∣G]≥φ(E[X∣G])\mathbb{E}[\varphi(X) \mid \mathcal{G}] \ge \varphi(\mathbb{E}[X \mid \mathcal{G}])E[φ(X)∣G]≥φ(E[X∣G]), which is Jensen's inequality from "Expectation, variance and inequalities" applied inside every block. With φ(x)=x2\varphi(x) = x^2φ(x)=x2 the gap in a block is the variance of XXX inside it: for X=ω2X = \omega^2X=ω2 on the block [0,12)[0, \tfrac12)[0,21​), E[X2∣block]=0.0125\mathbb{E}[X^2 \mid \text{block}] = 0.0125E[X2∣block]=0.0125, the square of the block average is (1/12)2=0.006944(1/12)^2 = 0.006944(1/12)2=0.006944, and the difference 1/180≈0.0055561/180 \approx 0.0055561/180≈0.005556 is the variance of ω2\omega^2ω2 within that half.

Summary

  • P(A∣B)=P(A∩B)/P(B)\mathbb{P}(A \mid B) = \mathbb{P}(A \cap B)/\mathbb{P}(B)P(A∣B)=P(A∩B)/P(B) shrinks the space to BBB and rescales; it is a probability measure, but P(A∣B)≠P(B∣A)\mathbb{P}(A \mid B) \ne \mathbb{P}(B \mid A)P(A∣B)=P(B∣A) in general.
  • The multiplication rule, the law of total probability and Bayes' rule follow from the definition; with a base rate of 1%, a positive result from a 99% sensitive, 95% specific test means illness with probability only 1/61/61/6.
  • Given a partition, E[X∣G]\mathbb{E}[X \mid \mathcal{G}]E[X∣G] replaces XXX by its average on each block, and the block averages average back to E[X]\mathbb{E}[X]E[X].
  • Given a σ-algebra, E[X∣G]\mathbb{E}[X \mid \mathcal{G}]E[X∣G] is the G\mathcal{G}G-measurable random variable with the same integral as XXX over every event of G\mathcal{G}G; it is unique up to a null set.
  • It is the best mean-squared prediction of XXX from G\mathcal{G}G: any other is worse by the squared distance to it, and more information never increases the error.
  • The rules: linearity, monotonicity, taking out what is known, the tower property, independence, conditional Jensen.
Try itOpen the conditional expectation lab
Previous · 11Modes of convergence and the law of large numbersNext · 13Measure theory in option pricing
Connections

Conditional probability and conditional expectation

Open the full graph
Builds on
05.11Modes of convergence and the law of large numbers05.07Probability spaces and Kolmogorov's axioms05.09Expectation, variance and inequalities05.10Independence and product measures05.02σ-algebras and Borel sets05.04Measurable functions
Leads to
05.13Measure theory in option pricing
See it in the knowledge graph
Labs for this lesson
Conditional Expectation