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/09

Expectation, variance and inequalities

Lesson 9 of 13 · 1 min read

The lesson "The Lebesgue integral" defined ∫f dμ\int f\,d\mu∫fdμ for any measurable function on any measure space, and "Random variables and their distributions" turned a random experiment into a number XXX with a distribution PX\mathbb{P}_XPX​ on the real line. This lesson joins the two. The expectation of a random variable is its Lebesgue integral under the probability measure, so everything proved about integrals earlier becomes a statement about averages of random quantities. Three questions drive the lesson: what a number such as 3.53.53.5 for a die really says, how to compute it without going back to the underlying space Ω\OmegaΩ, and how far a random variable can stray from its mean. The answers are the formula for E[g(X)]\mathbb{E}[g(X)]E[g(X)], the variance, and three inequalities, Markov's, Chebyshev's and Jensen's, which turn a mean and a variance into guarantees about probabilities.

Expectation as an integral

Let XXX be a random variable on a probability space (Ω,F,P)(\Omega, \mathcal{F}, \mathbb{P})(Ω,F,P). Its expectation, also called its mean or expected value, is the Lebesgue integral of XXX against P\mathbb{P}P:

E[X]=∫ΩX dP.\mathbb{E}[X] = \int_\Omega X\,d\mathbb{P}.E[X]=∫Ω​XdP.

For a simple random variable X=∑kak1AkX = \sum_k a_k \mathbf{1}_{A_k}X=∑k​ak​1Ak​​, the integral of "The Lebesgue integral" is the sum ∑kak P(Ak)\sum_k a_k\,\mathbb{P}(A_k)∑k​ak​P(Ak​): each value aka_kak​ is weighted by the probability of the event on which it is taken. A fair die is the model case. Take Ω={1,…,6}\Omega = \{1, \ldots, 6\}Ω={1,…,6} with mass 16\tfrac1661​ on each face and X(ω)=ωX(\omega) = \omegaX(ω)=ω. Then

E[X]=16⋅1+16⋅2+⋯+16⋅6=216=3.5.\mathbb{E}[X] = \tfrac16 \cdot 1 + \tfrac16 \cdot 2 + \cdots + \tfrac16 \cdot 6 = \tfrac{21}{6} = 3.5.E[X]=61​⋅1+61​⋅2+⋯+61​⋅6=621​=3.5.

The number 3.53.53.5 can be read in two ways, and both are worth keeping. The first is the long-run average: roll the die many times and the average of the results settles near 3.53.53.5. A later lesson of this track proves this as the law of large numbers; here it serves as the intuition. The second reading is a balance point. Put the distribution of XXX on a beam as sand, a pile of mass 16\tfrac1661​ at each of 1,…,61, \ldots, 61,…,6, and the beam balances on a pivot at 3.53.53.5. The mean is the centre of mass of the distribution.

Neither reading says that 3.53.53.5 is a likely or even a possible outcome, and a die never shows it. The mean describes where the distribution is centred, not what to expect on a single roll.

The integral of "The Lebesgue integral" does not always give a finite number, and the same care applies here. If X≥0X \ge 0X≥0, then E[X]\mathbb{E}[X]E[X] always exists, possibly as +∞+\infty+∞. For a general XXX, split X=X+−X−X = X^+ - X^-X=X+−X− into its positive and negative parts. The expectation is E[X+]−E[X−]\mathbb{E}[X^+] - \mathbb{E}[X^-]E[X+]−E[X−] whenever at least one of the two terms is finite, and XXX is integrable when both are, which is the same as E∣X∣<∞\mathbb{E}|X| < \inftyE∣X∣<∞. Linearity, monotonicity and the fact that changing XXX on a set of probability zero changes nothing all carry over from the integral, and so does ∣E[X]∣≤E∣X∣|\mathbb{E}[X]| \le \mathbb{E}|X|∣E[X]∣≤E∣X∣. For a constant, E[c]=c\mathbb{E}[c] = cE[c]=c, because the total mass is 111.

Computing expectations from the distribution

The definition integrates over Ω\OmegaΩ, but Ω\OmegaΩ is often out of sight. For a dart thrown at a square it is the square, for an endless sequence of coin tosses it is a set of binary digit sequences, and the point of "Random variables and their distributions" was that the distribution PX\mathbb{P}_XPX​ on the real line carries what matters about XXX. The expectation can be computed from the distribution alone. For a measurable function ggg,

E[g(X)]=∫Ωg(X) dP=∫Rg(x) dPX(x).\mathbb{E}[g(X)] = \int_\Omega g(X)\,d\mathbb{P} = \int_{\mathbb{R}} g(x)\,d\mathbb{P}_X(x).E[g(X)]=∫Ω​g(X)dP=∫R​g(x)dPX​(x).

Taking g(x)=xg(x) = xg(x)=x gives the mean from the distribution, and g(x)=x2g(x) = x^2g(x)=x2 gives the second moment, which is needed below. The proof follows the pattern used for every statement about integrals: indicators, then simple functions, then non-negative functions.

  1. Indicators. For g=1Bg = \mathbf{1}_Bg=1B​ with BBB a Borel set, 1B(X)\mathbf{1}_B(X)1B​(X) equals 1 exactly when X∈BX \in BX∈B, so E[1B(X)]=P(X∈B)=PX(B)=∫1B dPX\mathbb{E}[\mathbf{1}_B(X)] = \mathbb{P}(X \in B) = \mathbb{P}_X(B) = \int \mathbf{1}_B\,d\mathbb{P}_XE[1B​(X)]=P(X∈B)=PX​(B)=∫1B​dPX​. This is the definition of the image measure from "Measurable functions".
  2. Simple functions. A simple g=∑kbk1Bkg = \sum_k b_k \mathbf{1}_{B_k}g=∑k​bk​1Bk​​ is a finite combination of indicators, and both sides of the formula are linear in ggg, so the first stage gives the second.
  3. Non-negative functions. Choose simple functions gn↑gg_n \uparrow ggn​↑g, the dyadic staircases of "Measurable functions". Then gn(X)↑g(X)g_n(X) \uparrow g(X)gn​(X)↑g(X), and monotone convergence from "Convergence theorems" lets the limit pass inside the integral on both sides, so the formula holds for ggg.
  4. General functions. Apply the result to g+g^+g+ and g−g^-g− separately and subtract.

Two consequences follow. First, E[g(X)]\mathbb{E}[g(X)]E[g(X)] depends on XXX only through its distribution: two random variables with the same distribution, even on different probability spaces, have the same expectation. Second, the integral against PX\mathbb{P}_XPX​ is one of the concrete integrals of "The Lebesgue integral", and which one depends on the shape of the distribution:

  • A distribution made of atoms only (a discrete one): E[g(X)]=∑xg(x) P(X=x)\mathbb{E}[g(X)] = \sum_x g(x)\,\mathbb{P}(X = x)E[g(X)]=∑x​g(x)P(X=x), a sum over the possible values.
  • A distribution with a density fff: E[g(X)]=∫g(x)f(x) dx\mathbb{E}[g(X)] = \int g(x) f(x)\,dxE[g(X)]=∫g(x)f(x)dx.
  • A mixed distribution: the sum for the atoms plus the integral for the density part.

The waiting time at the traffic light of "Random variables and their distributions" is a mixed case. With probability 0.70.70.7 the light is green and X=0X = 0X=0; otherwise XXX is exponential with mean 222 minutes. The distribution is a point mass of size 0.70.70.7 at 000 plus a density part of total mass 0.30.30.3, so

E[X]=0.7⋅0+0.3∫0∞x 12e−x/2 dx=0.7⋅0+0.3⋅2=0.6.\mathbb{E}[X] = 0.7 \cdot 0 + 0.3 \int_0^\infty x\,\tfrac12 e^{-x/2}\,dx = 0.7 \cdot 0 + 0.3 \cdot 2 = 0.6.E[X]=0.7⋅0+0.3∫0∞​x21​e−x/2dx=0.7⋅0+0.3⋅2=0.6.

On average a driver waits 0.60.60.6 minutes, although most drivers wait not at all and the rest wait about two minutes. The same distribution gives E[X2]=0.7⋅0+0.3⋅8=2.4\mathbb{E}[X^2] = 0.7 \cdot 0 + 0.3 \cdot 8 = 2.4E[X2]=0.7⋅0+0.3⋅8=2.4, since an exponential with mean 222 has second moment 2⋅22=82 \cdot 2^2 = 82⋅22=8 (the case of mean 111 is computed in the section on variance).

The dart board of "The Lebesgue integral" is an example on a continuous space. A dart lands uniformly on the unit square, which has area 1, so probability equals area. The board has concentric rings around the centre of the square with outer radii 0.10.10.1, 0.250.250.25, 0.40.40.4 and 0.50.50.5, scoring 101010, 555, 222 and 111 points, and the corners score 000. The score is a simple function, so its expectation is each score times the probability of its ring, which is the ring's area π(router2−rinner2)\pi(r_{\text{outer}}^2 - r_{\text{inner}}^2)π(router2​−rinner2​):

E[score]=π (10⋅0.01+5⋅0.0525+2⋅0.0975+1⋅0.09)=0.6475 π≈2.0342.\mathbb{E}[\text{score}] = \pi\,(10 \cdot 0.01 + 5 \cdot 0.0525 + 2 \cdot 0.0975 + 1 \cdot 0.09) = 0.6475\,\pi \approx 2.0342.E[score]=π(10⋅0.01+5⋅0.0525+2⋅0.0975+1⋅0.09)=0.6475π≈2.0342.

A throw scores 000, 111, 222, 555 or 101010, and no throw scores 2.03422.03422.0342. The number is the long-run average score per throw.

The tail formula

For a non-negative random variable there is a second way to compute the mean, which uses only the probabilities P(X>t)\mathbb{P}(X > t)P(X>t) of exceeding each level ttt. The layer-cake formula of "The Lebesgue integral", ∫f dμ=∫0∞μ(f>t) dt\int f\,d\mu = \int_0^\infty \mu(f > t)\,dt∫fdμ=∫0∞​μ(f>t)dt, applied with μ=P\mu = \mathbb{P}μ=P and f=Xf = Xf=X, says

E[X]=∫0∞P(X>t) dt(X≥0).\mathbb{E}[X] = \int_0^\infty \mathbb{P}(X > t)\,dt \qquad (X \ge 0).E[X]=∫0∞​P(X>t)dt(X≥0).

Think of the value of XXX as a stack of thin layers, one for each height ttt between 000 and XXX. The layer at height ttt is present exactly when X>tX > tX>t, which has probability P(X>t)\mathbb{P}(X > t)P(X>t), so the average height of the stack is the sum of these probabilities over all heights. The function t↦P(X>t)t \mapsto \mathbb{P}(X > t)t↦P(X>t) is the tail of the distribution. It starts at 111 or a little below and decreases to 000 when XXX is finite, and the mean is the area under it.

For the exponential law with mean 111, P(X>t)=e−t\mathbb{P}(X > t) = e^{-t}P(X>t)=e−t, and ∫0∞e−t dt=1\int_0^\infty e^{-t}\,dt = 1∫0∞​e−tdt=1 is the mean, found with no integration by parts. For the fair die the tail is a staircase: for ttt in [k,k+1)[k, k+1)[k,k+1) with k=0,…,5k = 0, \ldots, 5k=0,…,5, P(X>t)=6−k6\mathbb{P}(X > t) = \tfrac{6-k}{6}P(X>t)=66−k​, a step of width 111, so

E[X]=∑k=05P(X>k)=6+5+4+3+2+16=3.5.\mathbb{E}[X] = \sum_{k=0}^{5} \mathbb{P}(X > k) = \frac{6 + 5 + 4 + 3 + 2 + 1}{6} = 3.5.E[X]=k=0∑5​P(X>k)=66+5+4+3+2+1​=3.5.

This is the same 3.53.53.5 as before, reached by a different cut. The earlier computation sliced the average into columns, one per value of XXX; this one slices it into layers, one per level. Using P(X≥t)\mathbb{P}(X \ge t)P(X≥t) instead of P(X>t)\mathbb{P}(X > t)P(X>t) gives the same integral, because the two functions differ at only countably many ttt, the atoms of the distribution. The formula is useful whenever tail probabilities are easier to find than a density, and it prepares the inequalities below, which are statements about tails.

Linearity and the indicator trick

Linearity of the integral gives, for integrable XXX and YYY on the same probability space and any constants aaa and bbb,

E[aX+bY]=a E[X]+b E[Y].\mathbb{E}[aX + bY] = a\,\mathbb{E}[X] + b\,\mathbb{E}[Y].E[aX+bY]=aE[X]+bE[Y].

No assumption about how XXX and YYY are related is needed. They can be identical, opposite or tangled together in any way: a sum of two functions on Ω\OmegaΩ is integrated by integrating each and adding. This is unusual, since most statements about several random variables need a condition on how they interact. The tool that makes linearity useful is the indicator. For an event AAA,

E[1A]=1⋅P(A)+0⋅P(Ac)=P(A).\mathbb{E}[\mathbf{1}_A] = 1 \cdot \mathbb{P}(A) + 0 \cdot \mathbb{P}(A^c) = \mathbb{P}(A).E[1A​]=1⋅P(A)+0⋅P(Ac)=P(A).

A random count is a sum of indicators, one for each thing counted, and its mean is the sum of the probabilities, however tangled the things are. Roll a die ten times and let NNN be the number of sixes. Then N=∑i=1101{roll i is a six}N = \sum_{i=1}^{10} \mathbf{1}_{\{\text{roll } i \text{ is a six}\}}N=∑i=110​1{roll i is a six}​, and

E[N]=∑i=110P(roll i is a six)=10⋅16≈1.667.\mathbb{E}[N] = \sum_{i=1}^{10} \mathbb{P}(\text{roll } i \text{ is a six}) = 10 \cdot \tfrac16 \approx 1.667.E[N]=i=1∑10​P(roll i is a six)=10⋅61​≈1.667.

Here the rolls do not influence each other, but the computation never used that, and the next example shows why this matters. A secretary has nnn letters and nnn addressed envelopes and puts the letters into the envelopes in random order, every arrangement being equally likely. Let MMM be the number of letters that land in their own envelope. Letter iii is equally likely to land in any of the nnn envelopes, so it lands in its own with probability 1n\tfrac1nn1​, and

E[M]=∑i=1n1n=n⋅1n=1for every n.\mathbb{E}[M] = \sum_{i=1}^{n} \frac1n = n \cdot \frac1n = 1 \qquad \text{for every } n.E[M]=i=1∑n​n1​=n⋅n1​=1for every n.

The events influence each other: if the first n−1n - 1n−1 letters are in their own envelopes, the last one must be too. The distribution of MMM is complicated, and yet its mean is 111 for three letters and for a hundred. For n=3n = 3n=3 the six arrangements can be listed: the identity has 333 correct letters, each of the three swaps of two letters has 111, and the two cyclic shifts have 000, so the mean is (3+1+1+1+0+0)/6=1(3 + 1 + 1 + 1 + 0 + 0)/6 = 1(3+1+1+1+0+0)/6=1.

Linearity does not extend to products. In general E[XY]≠E[X] E[Y]\mathbb{E}[XY] \ne \mathbb{E}[X]\,\mathbb{E}[Y]E[XY]=E[X]E[Y]: for the die, E[X⋅X]=91/6≈15.17\mathbb{E}[X \cdot X] = 91/6 \approx 15.17E[X⋅X]=91/6≈15.17, while E[X]2=12.25\mathbb{E}[X]^2 = 12.25E[X]2=12.25. The next lesson, "Independence and product measures", shows which extra condition makes the product rule true.

Infinite expectations and expectations that do not exist

A non-negative random variable always has an expectation, but it can be infinite, even when the variable is finite with probability one. The St Petersburg game shows how. A fair coin is tossed until the first head. If the first head comes on toss kkk, which has probability 2−k2^{-k}2−k, the prize is 2k2^k2k: a prize of 222 with probability 12\tfrac1221​, of 444 with probability 14\tfrac1441​, of 888 with probability 18\tfrac1881​, and so on. Every outcome gives a finite prize, yet

E[X]=∑k=1∞2k⋅2−k=1+1+1+⋯=∞.\mathbb{E}[X] = \sum_{k=1}^{\infty} 2^k \cdot 2^{-k} = 1 + 1 + 1 + \cdots = \infty.E[X]=k=1∑∞​2k⋅2−k=1+1+1+⋯=∞.

Each possible number of tosses adds one unit to the mean. If the game is stopped after at most mmm tosses, with prize 000 when no head has appeared by then, the mean is exactly mmm: 202020 for m=20m = 20m=20, and a million for a million tosses. Without a cutoff the mean grows past every bound, because the rare huge prizes carry as much weight as the common small ones. No finite amount is a fair average.

A variable that takes both signs has a second way to fail. The Cauchy law has density f(x)=1π(1+x2)f(x) = \dfrac{1}{\pi(1 + x^2)}f(x)=π(1+x2)1​ on the whole line. It is a proper density, with total mass 1π [arctan⁡x]−∞∞=1\tfrac1\pi\,[\arctan x]_{-\infty}^{\infty} = 1π1​[arctanx]−∞∞​=1, but

E∣X∣=2π∫0∞x1+x2 dx=1π[ln⁡(1+x2)]0∞=∞.\mathbb{E}|X| = \frac{2}{\pi}\int_0^\infty \frac{x}{1 + x^2}\,dx = \frac{1}{\pi}\big[\ln(1 + x^2)\big]_0^\infty = \infty.E∣X∣=π2​∫0∞​1+x2x​dx=π1​[ln(1+x2)]0∞​=∞.

Both E[X+]\mathbb{E}[X^+]E[X+] and E[X−]\mathbb{E}[X^-]E[X−] are infinite, so E[X+]−E[X−]\mathbb{E}[X^+] - \mathbb{E}[X^-]E[X+]−E[X−] would be ∞−∞\infty - \infty∞−∞, and there is no mean. Symmetry suggests 000, but symmetry cancels the two infinite halves only after one decides how to cut them, and a different cut gives a different answer; the integral refuses to choose. The practical symptom is that averages of more and more Cauchy values never settle down. This is why the definition asks for E∣X∣<∞\mathbb{E}|X| < \inftyE∣X∣<∞ before it speaks of the mean of a variable with both signs.

Variance and moments

The mean locates a distribution but says nothing about its spread. A variable that equals 3.53.53.5 with certainty and a fair die have the same mean and little else in common. The usual measure of spread is the average squared distance from the mean. For XXX with E[X2]<∞\mathbb{E}[X^2] < \inftyE[X2]<∞ and mean μ\muμ, the variance and the standard deviation are

Var⁡(X)=E[(X−μ)2],σ=Var⁡(X).\operatorname{Var}(X) = \mathbb{E}\big[(X - \mu)^2\big], \qquad \sigma = \sqrt{\operatorname{Var}(X)}.Var(X)=E[(X−μ)2],σ=Var(X)​.

Squaring makes every deviation count positively, so deviations above and below the mean do not cancel, and it keeps the algebra clean. The square root undoes the squaring, so σ\sigmaσ has the same unit as XXX. The variance is an expectation like any other, ∫(x−μ)2 dPX(x)\int (x - \mu)^2\,d\mathbb{P}_X(x)∫(x−μ)2dPX​(x), and is computed from the distribution. Expanding the square and using linearity gives a shortcut. First,

(X−μ)2=X2−2μX+μ2.(X - \mu)^2 = X^2 - 2\mu X + \mu^2.(X−μ)2=X2−2μX+μ2.

Now take expectations of each term. The mean μ\muμ is a constant, so E[2μX]=2μ E[X]=2μ2\mathbb{E}[2\mu X] = 2\mu\,\mathbb{E}[X] = 2\mu^2E[2μX]=2μE[X]=2μ2 and E[μ2]=μ2\mathbb{E}[\mu^2] = \mu^2E[μ2]=μ2:

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

For the die, E[X2]=1+4+9+16+25+366=916≈15.17\mathbb{E}[X^2] = \tfrac{1 + 4 + 9 + 16 + 25 + 36}{6} = \tfrac{91}{6} \approx 15.17E[X2]=61+4+9+16+25+36​=691​≈15.17 and (EX)2=12.25(\mathbb{E}X)^2 = 12.25(EX)2=12.25, so Var⁡(X)=3512≈2.917\operatorname{Var}(X) = \tfrac{35}{12} \approx 2.917Var(X)=1235​≈2.917 and σ≈1.708\sigma \approx 1.708σ≈1.708. For the exponential law with mean 111, integration by parts twice gives E[X2]=∫0∞x2e−x dx=2\mathbb{E}[X^2] = \int_0^\infty x^2 e^{-x}\,dx = 2E[X2]=∫0∞​x2e−xdx=2, so Var⁡(X)=2−1=1\operatorname{Var}(X) = 2 - 1 = 1Var(X)=2−1=1 and σ=1\sigma = 1σ=1. For the traffic light, Var⁡(X)=2.4−0.62=2.04\operatorname{Var}(X) = 2.4 - 0.6^2 = 2.04Var(X)=2.4−0.62=2.04 and σ≈1.428\sigma \approx 1.428σ≈1.428, more than twice the mean, which reflects many zeros and a few long waits.

The variance is zero only for a constant: E[(X−μ)2]=0\mathbb{E}[(X - \mu)^2] = 0E[(X−μ)2]=0 forces (X−μ)2=0(X - \mu)^2 = 0(X−μ)2=0 almost surely, by the rule from "The Lebesgue integral" that a non-negative function with integral zero vanishes almost everywhere. Shifting and scaling behave simply. If Y=aX+bY = aX + bY=aX+b, then E[Y]=aμ+b\mathbb{E}[Y] = a\mu + bE[Y]=aμ+b, so Y−E[Y]=a(X−μ)Y - \mathbb{E}[Y] = a(X - \mu)Y−E[Y]=a(X−μ) and

Var⁡(aX+b)=E[a2(X−μ)2]=a2Var⁡(X).\operatorname{Var}(aX + b) = \mathbb{E}\big[a^2 (X - \mu)^2\big] = a^2 \operatorname{Var}(X).Var(aX+b)=E[a2(X−μ)2]=a2Var(X).

Adding a constant slides the whole distribution without changing its spread, and multiplying by aaa multiplies the standard deviation by ∣a∣|a|∣a∣. For Y=2X+1Y = 2X + 1Y=2X+1 with XXX a die, Var⁡(Y)=4⋅3512=353≈11.67\operatorname{Var}(Y) = 4 \cdot \tfrac{35}{12} = \tfrac{35}{3} \approx 11.67Var(Y)=4⋅1235​=335​≈11.67. How variance behaves for a sum of two random variables is the subject of "Independence and product measures".

The numbers E[Xp]\mathbb{E}[X^p]E[Xp] are the moments of XXX, and the mean and the second moment are the first two. The random variables with E∣X∣p<∞\mathbb{E}|X|^p < \inftyE∣X∣p<∞ are said to lie in LpL^pLp; for p=1p = 1p=1 these are the integrable ones. A variable can have a mean and no variance, but on a probability space a finite higher moment always forces the lower ones to be finite. For p=2p = 2p=2 the reason is the inequality ∣x∣≤1+x2|x| \le 1 + x^2∣x∣≤1+x2, valid for every real xxx: when ∣x∣≤1|x| \le 1∣x∣≤1 the right side is at least 111, and when ∣x∣>1|x| > 1∣x∣>1 we have ∣x∣<x2|x| < x^2∣x∣<x2. Taking expectations gives E∣X∣≤1+E[X2]<∞\mathbb{E}|X| \le 1 + \mathbb{E}[X^2] < \inftyE∣X∣≤1+E[X2]<∞, where the 111 is E[1]\mathbb{E}[1]E[1], finite because the total mass is 111. A finite variance therefore guarantees a mean. On the whole line with Lebesgue measure the constant 111 is not integrable, and the implication fails.

Markov's inequality

How much probability can sit far from the mean? For a variable that is never negative, the mean alone already limits it. Markov's inequality says that for X≥0X \ge 0X≥0 and any a>0a > 0a>0,

P(X≥a)≤E[X]a.\mathbb{P}(X \ge a) \le \frac{\mathbb{E}[X]}{a}.P(X≥a)≤aE[X]​.

If the average is 333 and the values are never negative, at most 3/9=133/9 = \tfrac133/9=31​ of the probability can lie at 999 or beyond. Picture the sand on the beam, which starts at 000 and extends to the right. Sand beyond aaa sits at least aaa away from the left end, so every unit of it pushes the balance point at least aaa to the right; with too much of it out there, the balance point could not stay at E[X]\mathbb{E}[X]E[X].

The proof is a comparison of two functions. For X≥0X \ge 0X≥0 and a>0a > 0a>0,

a 1{X≥a}≤Xa\,\mathbf{1}_{\{X \ge a\}} \le Xa1{X≥a}​≤X

holds at every outcome: where X≥aX \ge aX≥a the left side is a≤Xa \le Xa≤X, and elsewhere it is 0≤X0 \le X0≤X because XXX is not negative. Expectation is monotone and E[1{X≥a}]=P(X≥a)\mathbb{E}[\mathbf{1}_{\{X \ge a\}}] = \mathbb{P}(X \ge a)E[1{X≥a}​]=P(X≥a), so a P(X≥a)≤E[X]a\,\mathbb{P}(X \ge a) \le \mathbb{E}[X]aP(X≥a)≤E[X], and dividing by aaa finishes the proof.

The inequality uses nothing but the mean, so it has to hold for every distribution with that mean, and it is often far from the truth. For the exponential law with mean 111 and a=3a = 3a=3, the true tail is P(X≥3)=e−3≈0.0498\mathbb{P}(X \ge 3) = e^{-3} \approx 0.0498P(X≥3)=e−3≈0.0498, while Markov gives E[X]/a=1/3≈0.3333\mathbb{E}[X]/a = 1/3 \approx 0.3333E[X]/a=1/3≈0.3333, nearly seven times larger. It is not wasteful for every law. The two-point law with mass 23\tfrac2332​ at 000 and 13\tfrac1331​ at 333 has mean 111 and P(X≥3)=13\mathbb{P}(X \ge 3) = \tfrac13P(X≥3)=31​, exactly the bound, so no better bound can be had from the mean alone. For a≤E[X]a \le \mathbb{E}[X]a≤E[X] the bound is at least 111 and says nothing.

Chebyshev's inequality

Markov's inequality controls one side of a non-negative variable. To control the distance from the mean on both sides, apply it to the non-negative variable (X−μ)2(X - \mu)^2(X−μ)2, whose mean is the variance, at the level a=k2σ2a = k^2\sigma^2a=k2σ2. The event ∣X−μ∣≥kσ|X - \mu| \ge k\sigma∣X−μ∣≥kσ is the same event as (X−μ)2≥k2σ2(X - \mu)^2 \ge k^2\sigma^2(X−μ)2≥k2σ2, so for σ>0\sigma > 0σ>0 and k>0k > 0k>0,

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

This is Chebyshev's inequality. Whatever the distribution, at most 14\tfrac1441​ of the probability lies two standard deviations or more from the mean, at most 19\tfrac1991​ three or more, and at most 116\tfrac1{16}161​ four or more. The standard deviation becomes a ruler for rare events, and the only ingredients are the mean and the variance.

For the die, μ=3.5\mu = 3.5μ=3.5 and σ≈1.708\sigma \approx 1.708σ≈1.708. The event ∣X−3.5∣≥2.5|X - 3.5| \ge 2.5∣X−3.5∣≥2.5 consists of the faces 111 and 666, so its probability is 13\tfrac1331​, while Chebyshev, with k=2.5/σk = 2.5/\sigmak=2.5/σ, gives σ2/2.52≈0.4667\sigma^2/2.5^2 \approx 0.4667σ2/2.52≈0.4667. For the exponential law with mean 111 and standard deviation 111, take k=2k = 2k=2: the event ∣X−1∣≥2|X - 1| \ge 2∣X−1∣≥2 is X≥3X \ge 3X≥3, because X≤−1X \le -1X≤−1 is impossible, with probability e−3≈0.0498e^{-3} \approx 0.0498e−3≈0.0498 against the bound 14\tfrac1441​. Even for the normal law the bound is generous, since two standard deviations leave about 0.04550.04550.0455 in both tails together.

Is the bound as good as it can be when only the mean and variance are known? It is. For k≥1k \ge 1k≥1, take the three-point law with masses 12k2\tfrac{1}{2k^2}2k21​, 1−1k21 - \tfrac{1}{k^2}1−k21​ and 12k2\tfrac{1}{2k^2}2k21​ at μ−kσ\mu - k\sigmaμ−kσ, μ\muμ and μ+kσ\mu + k\sigmaμ+kσ. By symmetry its mean is μ\muμ. Its variance is (kσ)2⋅2⋅12k2=σ2(k\sigma)^2 \cdot 2 \cdot \tfrac{1}{2k^2} = \sigma^2(kσ)2⋅2⋅2k21​=σ2, and P(∣X−μ∣≥kσ)=1k2\mathbb{P}(|X - \mu| \ge k\sigma) = \tfrac{1}{k^2}P(∣X−μ∣≥kσ)=k21​, exactly the bound. For each kkk some law with that mean and variance reaches it, so no smaller number can replace 1/k21/k^21/k2 in a statement that uses only μ\muμ and σ\sigmaσ.

The figure compares the true tail with the bound. Choose a law and a bound, then move the slider: aaa for Markov, where the plot shows P(X≥a)\mathbb{P}(X \ge a)P(X≥a) against E[X]/a\mathbb{E}[X]/aE[X]/a, or kkk for Chebyshev, where it shows P(∣X−μ∣≥kσ)\mathbb{P}(|X - \mu| \ge k\sigma)P(∣X−μ∣≥kσ) against 1/k21/k^21/k2. The solid curve always stays below the dashed one. With the exponential law and Markov at the default a=3a = 3a=3, the readouts show 0.04980.04980.0498 against 0.33330.33330.3333, a ratio of about 6.706.706.70; switching to Chebyshev at k=2k = 2k=2 gives 0.04980.04980.0498 against 0.250.250.25, a ratio of about 5.025.025.02. The die draws a staircase with a jump at every face. The last law changes with the slider: it is the two-point law for Markov or the three-point law for Chebyshev that attains the bound at the marked value, where the solid curve touches the dashed one and the ratio is exactly 111.

Tail probabilities against the Markov and Chebyshev boundsOpen in Lebesgue Integral
3.00
0.56
ℙ(X ≥ a)𝔼X / aCurrent value
μ
1.000
σ
1.000
True probability
0.0498
Bound
0.3333
Bound / true
6.70

The solid curve is ℙ(X ≥ a), the dashed one 𝔼X / a, capped at 1. Move a: the bound always lies above the curve, and far from a = 𝔼X it is loose.

Worked example

The die: mean, variance and Chebyshev

  1. The mean of a fair die:

    E[X]=1+2+3+4+5+66\displaystyle \mathbb{E}[X] = \tfrac{1 + 2 + 3 + 4 + 5 + 6}{6}E[X]=61+2+3+4+5+6​=3.5
  2. The second moment:

    E[X2]=1+4+9+16+25+366\displaystyle \mathbb{E}[X^2] = \tfrac{1 + 4 + 9 + 16 + 25 + 36}{6}E[X2]=61+4+9+16+25+36​=15.1667
  3. The variance, by the shortcut formula:

    916−3.52\displaystyle \tfrac{91}{6} - 3.5^2691​−3.52=2.9167
  4. The standard deviation:

    σ=35/12\displaystyle \sigma = \sqrt{35/12}σ=35/12​=1.7078
  5. The true probability that the roll is at least 2.52.52.5 from the mean, which means a 111 or a 666:

    P(∣X−3.5∣≥2.5)=26\displaystyle \mathbb{P}(|X - 3.5| \ge 2.5) = \tfrac26P(∣X−3.5∣≥2.5)=62​=0.3333
  6. Chebyshev's bound for the same event:

    σ2/2.52\displaystyle \sigma^2 / 2.5^2σ2/2.52=0.4667
  7. Markov's bound for P(X≥6)\mathbb{P}(X \ge 6)P(X≥6):

    E[X]/6\displaystyle \mathbb{E}[X]/6E[X]/6=0.5833
  8. The true probability of rolling a 666, for comparison:

    P(X≥6)\displaystyle \mathbb{P}(X \ge 6)P(X≥6)=0.1667

Jensen's inequality

The last inequality compares the average of a function with the function of the average. A function φ\varphiφ is convex if every chord between two points of its graph lies above the graph:

φ(tx+(1−t)y)≤t φ(x)+(1−t) φ(y)(0≤t≤1).\varphi\big(tx + (1 - t)y\big) \le t\,\varphi(x) + (1 - t)\,\varphi(y) \qquad (0 \le t \le 1).φ(tx+(1−t)y)≤tφ(x)+(1−t)φ(y)(0≤t≤1).

Read this as an expectation. Let XXX equal xxx with probability ttt and yyy with probability 1−t1 - t1−t. Then tx+(1−t)ytx + (1-t)ytx+(1−t)y is E[X]\mathbb{E}[X]E[X] and the right side is E[φ(X)]\mathbb{E}[\varphi(X)]E[φ(X)], so the statement is φ(E[X])≤E[φ(X)]\varphi(\mathbb{E}[X]) \le \mathbb{E}[\varphi(X)]φ(E[X])≤E[φ(X)]. Jensen's inequality says the same for every integrable random variable XXX with φ(X)\varphi(X)φ(X) integrable and every convex φ\varphiφ. In a picture: the average of points on a convex curve lies above the curve, at the average position.

The proof for a general XXX replaces the chord by a tangent. A convex function lies above its tangent lines, so at m=E[X]m = \mathbb{E}[X]m=E[X] there is a slope ccc (at a corner of the graph, any slope between the left and right slopes) with

φ(x)≥φ(m)+c (x−m)for all x.\varphi(x) \ge \varphi(m) + c\,(x - m) \qquad \text{for all } x.φ(x)≥φ(m)+c(x−m)for all x.

Put x=Xx = Xx=X and take expectations. The term E[X−m]\mathbb{E}[X - m]E[X−m] vanishes, and what remains is Jensen's inequality:

E[φ(X)]≥φ(m)+c E[X−m]=φ(m)=φ(E[X]).\mathbb{E}[\varphi(X)] \ge \varphi(m) + c\,\mathbb{E}[X - m] = \varphi(m) = \varphi\big(\mathbb{E}[X]\big).E[φ(X)]≥φ(m)+cE[X−m]=φ(m)=φ(E[X]).

Three consequences come back constantly. With φ(x)=x2\varphi(x) = x^2φ(x)=x2 the inequality reads E[X2]≥(EX)2\mathbb{E}[X^2] \ge (\mathbb{E}X)^2E[X2]≥(EX)2, which says that the variance is not negative; the variance is exactly the gap in Jensen's inequality for x2x^2x2. For the die, E[X2]=91/6≈15.17≥12.25=(EX)2\mathbb{E}[X^2] = 91/6 \approx 15.17 \ge 12.25 = (\mathbb{E}X)^2E[X2]=91/6≈15.17≥12.25=(EX)2, and the gap is 35/1235/1235/12. With φ(x)=∣x∣\varphi(x) = |x|φ(x)=∣x∣ it gives ∣EX∣≤E∣X∣|\mathbb{E}X| \le \mathbb{E}|X|∣EX∣≤E∣X∣. With φ(x)=ex\varphi(x) = e^xφ(x)=ex it gives E[eX]≥eEX\mathbb{E}[e^X] \ge e^{\mathbb{E}X}E[eX]≥eEX: for the die, E[eX]=e+e2+⋯+e66≈106.1\mathbb{E}[e^X] = \tfrac{e + e^2 + \cdots + e^6}{6} \approx 106.1E[eX]=6e+e2+⋯+e6​≈106.1, far above e3.5≈33.12e^{3.5} \approx 33.12e3.5≈33.12.

For a concave function the inequality turns around, and it is a warning against a common mistake: in general E[g(X)]≠g(E[X])\mathbb{E}[g(X)] \ne g(\mathbb{E}[X])E[g(X)]=g(E[X]). For the concave g(x)=xg(x) = \sqrt{x}g(x)=x​ and a die, EX≈1.805\mathbb{E}\sqrt{X} \approx 1.805EX​≈1.805, below 3.5≈1.871\sqrt{3.5} \approx 1.8713.5​≈1.871. The two agree only for affine g(x)=ax+bg(x) = ax + bg(x)=ax+b, which is linearity again.

Summary

  • The expectation E[X]=∫X dP\mathbb{E}[X] = \int X\,d\mathbb{P}E[X]=∫XdP is the Lebesgue integral under a probability measure: the long-run average, and the balance point of the distribution. It exists for X≥0X \ge 0X≥0 (possibly infinite) and for integrable XXX.
  • E[g(X)]=∫g dPX\mathbb{E}[g(X)] = \int g\,d\mathbb{P}_XE[g(X)]=∫gdPX​ computes it from the distribution: a sum for atoms, ∫gf dx\int g f\,dx∫gfdx for a density, both for a mixed law. For X≥0X \ge 0X≥0, E[X]=∫0∞P(X>t) dt\mathbb{E}[X] = \int_0^\infty \mathbb{P}(X > t)\,dtE[X]=∫0∞​P(X>t)dt.
  • Expectation is linear with no condition on XXX and YYY, and E[1A]=P(A)\mathbb{E}[\mathbf{1}_A] = \mathbb{P}(A)E[1A​]=P(A), so counts are averaged by adding probabilities. The mean can be infinite (St Petersburg) or not exist at all (Cauchy).
  • Var⁡(X)=E[X2]−(EX)2\operatorname{Var}(X) = \mathbb{E}[X^2] - (\mathbb{E}X)^2Var(X)=E[X2]−(EX)2 measures spread, Var⁡(aX+b)=a2Var⁡(X)\operatorname{Var}(aX + b) = a^2 \operatorname{Var}(X)Var(aX+b)=a2Var(X), and a finite second moment implies a finite first moment.
  • Markov: P(X≥a)≤E[X]/a\mathbb{P}(X \ge a) \le \mathbb{E}[X]/aP(X≥a)≤E[X]/a. Chebyshev: P(∣X−μ∣≥kσ)≤1/k2\mathbb{P}(|X - \mu| \ge k\sigma) \le 1/k^2P(∣X−μ∣≥kσ)≤1/k2, sharp for a three-point law. Jensen: φ(EX)≤Eφ(X)\varphi(\mathbb{E}X) \le \mathbb{E}\varphi(X)φ(EX)≤Eφ(X) for convex φ\varphiφ.
Try itOpen the Lebesgue integral lab
Previous · 08Random variables and their distributionsNext · 10Independence and product measures
Connections

Expectation, variance and inequalities

Open the full graph
Builds on
05.08Random variables and their distributions05.05The Lebesgue integral05.04Measurable functions05.06Convergence theorems
Leads to
05.10Independence and product measures05.11Modes of convergence and the law of large numbers05.12Conditional probability and conditional expectation05.13Measure theory in option pricing
See it in the knowledge graph
Labs for this lesson
Lebesgue Integral