Module contents
Lesson 17 of 24Core 90 min

Laws of large numbers

Why average loss on a test set estimates risk, and when it does not. Prove the weak and strong laws, study Kolmogorov’s 0-1 law and cases where the average fails to converge (Cauchy, St Petersburg), and extend the result to uniform convergence of the empirical distribution function using Glivenko–Cantelli and the DKW inequality.

After this lesson you can

  • Prove the weak law with Chebyshev and the strong law with the fourth moment and Borel–Cantelli.
  • State Etemadi’s strong law and Kolmogorov’s 0-1 law.
  • Identify distributions whose averages fail to converge or converge very slowly.
  • Prove the Glivenko–Cantelli theorem and apply the DKW inequality to construct confidence bands for the distribution function.

Before you start

Motivation: test error estimates risk, but with what guarantee?

You train a model, evaluate it on nn unseen examples and obtain mean loss 0.310.31. You write 0.310.31 in the report as if it were the model quality. Behind this is a probabilistic claim: mean loss on test examples, R^n=1n∑i=1nℓi\hat R_n = \frac{1}{n}\sum_{i=1}^{n}\ell_i, resembles risk R=E[ℓ]R = \E[\ell], expected loss under the real data distribution. This is the law of large numbers, underpinning every average: an evaluation, a stochastic gradient, a Monte Carlo integral or the frequency of an event in a log.

But the claim has fine print, which this lesson reads in full. Four questions will be answered with proofs and simulations.

  1. In what sense does R^n\hat R_n resemble RR? Using convergence modes from the previous lesson: in probability (weak law) or almost surely (strong law).
  2. Under what assumptions? Independence, identical distribution and an existing expectation. Which can be relaxed?
  3. How quickly? The law alone says nothing about rate. With finite variance error falls as 1/n1/\sqrt{n}; without it convergence may be arbitrarily slow.
  4. When does it fail? Some distributions have averages that converge to nothing; these are not just laboratory examples. Service latencies, portfolio losses and heavy-tailed gradients can resemble them.

A preliminary calculation sets the bar. If losses lie in [0,1][0, 1], then Var⁡(ℓ)≤1/4\Var(\ell) \le 1/4 and Chebyshev’s inequality gives, for n=104n = 10^4 test examples, P(∣R^n−R∣>0.02)≤1/4104⋅0.022=0.0625\Pr(\abs{\hat R_n - R} > 0.02) \le \frac{1/4}{10^4 \cdot 0.02^2} = 0.0625. This real quantitative guarantee takes one line to prove. It can be improved: in the Hoeffding lesson the same question is answered with 7⋅10−47\cdot 10^{-4}. All this assumes ℓi\ell_i are independent of the model; if you chose the model by inspecting the test set, ℓi\ell_i are no longer an independent sample and the law does not apply. Uniform convergence in the Glivenko-Cantelli section and learning theory module addresses this problem.

Throughout, X1,X2,…X_1, X_2, \dots are real random variables on the same probability space, Sn=X1+⋯+XnS_n = X_1 + \dots + X_n and Xˉn=Sn/n\bar X_n = S_n / n. The existence of an infinite sequence of independent variables with prescribed laws follows from the Kolmogorov extension theorem in lesson 7; here it is assumed.

Intuition: a race of means

Before proving anything, inspect average behavior. The figure runs 200 trajectories of Xˉn\bar X_n up to n=104n = 10^4, using logarithmic nn scale to fit all observations from first to last.

InteractiveRunning means race
Running means Xˉn\bar X_n of 24 of the 200 trajectories, up to n=104n = 10^4
μ = 1
  • highlighted path
  • other paths
  • μ
  • cone ±1.645σ/√n
  • 5–95% band of the 200
Typical error size: median of ∣Xˉn−μ∣|\bar X_n - \mu|
measured slope −0.50
  • median across all 200
  • theoretical slope −0.5
100
0.10
μ=E[X]\mu = \E[X]1
Var⁡(X)\Var(X)1
Measured slope (log-log)−0.50
Theoretical slope−0.5
P(∣Xˉn−μ∣>ε)\Pr(|\bar X_{n} - \mu| > \varepsilon) at n=100n = 100 (weak law)30.5 %
P(sup⁡n≤m≤104∣Xˉm−μ∣>ε)\Pr(\sup_{n \le m \le 10^4} |\bar X_m - \mu| > \varepsilon) (strong law)60.5 %
Largest summand's share of the sum (median)4.9 %
Start with the exponential: the trajectories (24 of 200) close in on μ=1\mu = 1 and almost all fit inside the dashed cone μ±1.645 σ/n\mu \pm 1.645\,\sigma/\sqrt{n} (the central limit theorem predicts 90%). On the right, median error on log-log axes has slope −1/2-1/2. Switch to Pareto 1.5, Pareto 0.8 and Cauchy and see what breaks: the slope, cone and largest summand's weight. Move nn and ε\varepsilon to compare two easily confused readings: probability of being outside the band at a particular nn (weak law), and probability of ever leaving it from nn onward (strong law).

What you should have seen:

  • With Bernoulli and exponential, error falls as n−1/2n^{-1/2}. Measured log-log slope is −0.5-0.5. Gaining one decimal digit requires multiplying nn by 100100, a rule valid whenever variance is finite.
  • With Pareto α=1.5\alpha = 1.5 the mean converges, but at another rate. Expectation is 33 and variance infinite. Slope is −1/3=1/α−1-1/3 = 1/\alpha - 1, not −1/2-1/2; the variance cone does not exist and trajectories jump: one enormous summand shifts them suddenly and takes time for the mean to absorb. With n=104n = 10^4 and ε=0.1\varepsilon = 0.1, over half the trajectories remain outside the band.
  • With Pareto α=0.8\alpha = 0.8 there is no limit. Expectation is infinite and the average grows as n1/α−1=n0.25n^{1/\alpha - 1} = n^{0.25}. The largest summand accounts for an appreciable fraction of the sum, measuring the problem’s severity.
  • With Cauchy there is no trend either. The 5–95% band does not narrow, median error is constant, and the mean of 10410^4 observations is no better than one. We will prove this.
  • Weak and strong laws are different readings. With the exponential, n=100n = 100 and ε=0.1\varepsilon = 0.1, about 30% of trajectories are outside the band at that nn (weak law), but nearly 60% leave it at some later time, between n=100n = 100 and n=104n = 10^4 (strong law; beyond 10410^4 little is added). Both tend to 00 as nn rises; the second does so more slowly because it controls the whole trajectory tail.

Weak law of large numbers

The weak law of large numbers (WLLN) says that under suitable assumptions Xˉn→μ\bar X_n \to \mu in probability: for every ε>0\varepsilon > 0, P(∣Xˉn−μ∣>ε)→0\Pr(\abs{\bar X_n - \mu} > \varepsilon) \to 0. The simplest version takes one line to prove, and that line gives more than promised.

Proof

By linearity, E[Xˉn]=μ\E[\bar X_n] = \mu, so E[(Xˉn−μ)2]=Var⁡(Xˉn)\E[(\bar X_n - \mu)^2] = \Var(\bar X_n). By the variance of a sum, Var⁡(Sn)=∑iVar⁡(Xi)+∑i≠jCov⁡(Xi,Xj)=∑iVar⁡(Xi)≤nσ2\Var(S_n) = \sum_i \Var(X_i) + \sum_{i \ne j}\Cov(X_i, X_j) = \sum_i \Var(X_i) \le n\sigma^2, because covariances vanish. Thus Var⁡(Xˉn)=Var⁡(Sn)/n2≤σ2/n\Var(\bar X_n) = \Var(S_n)/n^2 \le \sigma^2/n. Applying Chebyshev’s inequality to Xˉn\bar X_n gives the second bound.

∎

Note what was not used: independence, identical distribution, or even bounds on moments beyond the second. We gained a quantitative fact, σ2/(nε2)\sigma^2/(n\varepsilon^2), giving required sample size: the motivating bound.

What if there is no variance? Chebyshev fails, but finite expectation alone still suffices. The technique is truncation: cut each XiX_i at a level where it has variance, apply Chebyshev to the truncated part and show truncation almost never acts.

Proof

Fix ε>0\varepsilon > 0 and δ>0\delta > 0. For each nn define truncated variables Yi=Xi 1[∣Xi∣≤δn]Y_i = X_i\,\ind[\abs{X_i} \le \delta n] (depending on nn, omitted in the notation), Tn=Y1+⋯+YnT_n = Y_1 + \dots + Y_n and μn=E[Y1]\mu_n = \E[Y_1]. There are three things to check.

The truncated mean approaches μ\mu. Since ∣X11[∣X1∣≤δn]∣≤∣X1∣\abs{X_1\ind[\abs{X_1} \le \delta n]} \le \abs{X_1} is integrable, the dominated convergence theorem gives μn→μ\mu_n \to \mu. For sufficiently large nn, ∣μn−μ∣≤ε\abs{\mu_n - \mu} \le \varepsilon.

The truncated part satisfies the law by Chebyshev. Since Y12≤δn ∣Y1∣≤δn ∣X1∣Y_1^2 \le \delta n\,\abs{Y_1} \le \delta n\,\abs{X_1}, we have Var⁡(Y1)≤E[Y12]≤δn E∣X1∣\Var(Y_1) \le \E[Y_1^2] \le \delta n\,\E\abs{X_1}. The YiY_i are iid, so

P(∣Tn/n−μn∣>ε)≤Var⁡(Y1)nε2≤δ E∣X1∣ε2.\Pr\big(\abs{T_n/n - \mu_n} > \varepsilon\big) \le \frac{\Var(Y_1)}{n\varepsilon^2} \le \frac{\delta\,\E\abs{X_1}}{\varepsilon^2}.

Truncation almost never acts. P(Sn≠Tn)≤nP(∣X1∣>δn)=E[n 1[∣X1∣>δn]]≤1δE[∣X1∣1[∣X1∣>δn]]\Pr(S_n \ne T_n) \le n\Pr(\abs{X_1} > \delta n) = \E\big[n\,\ind[\abs{X_1} > \delta n]\big] \le \frac{1}{\delta}\E\big[\abs{X_1}\ind[\abs{X_1} > \delta n]\big], tending to 00 as n→∞n \to \infty (again by dominated convergence, since ∣X1∣\abs{X_1} is integrable).

If Sn=TnS_n = T_n, ∣Tn/n−μn∣≤ε\abs{T_n/n - \mu_n} \le \varepsilon and ∣μn−μ∣≤ε\abs{\mu_n - \mu} \le \varepsilon, then ∣Xˉn−μ∣≤2ε\abs{\bar X_n - \mu} \le 2\varepsilon. Thus for large nn,

P(∣Xˉn−μ∣>2ε)≤P(Sn≠Tn)+δ E∣X1∣ε2,\Pr\big(\abs{\bar X_n - \mu} > 2\varepsilon\big) \le \Pr(S_n \ne T_n) + \frac{\delta\,\E\abs{X_1}}{\varepsilon^2},

and, since the first term tends to 00,

lim sup⁡n→∞P(∣Xˉn−μ∣>2ε)≤δ E∣X1∣ε2.\limsup_{n\to\infty}\Pr\big(\abs{\bar X_n - \mu} > 2\varepsilon\big) \le \frac{\delta\,\E\abs{X_1}}{\varepsilon^2}.

The left side does not depend on arbitrary δ\delta: it equals 00.

∎

Truncation returns throughout limit theory. This proof also leaves a clue for later: what was actually used is not E∣X∣<∞\E\abs{X} < \infty, but nP(∣X∣>δn)→0n\Pr(\abs{X} > \delta n) \to 0 and convergence of truncated means. Feller showed xP(∣X∣>x)→0x\Pr(\abs{X} > x) \to 0 is necessary and sufficient for Xˉn−E[X1[∣X∣≤n]]\bar X_n - \E[X\ind[\abs{X} \le n]] to tend to 00 in probability. Thus some laws without finite expectation satisfy the weak law with suitable centering, as in the next section’s example. St Petersburg does not satisfy the condition (xP(X>x)x\Pr(X > x) oscillates between 11 and 22), but Feller’s version for normalizations bnb_n other than nn recovers it with bn=nlog⁡2nb_n = n\log_2 n, as shown below.

Strong law of large numbers

The weak law says that for each large nn, Xˉn\bar X_n is unlikely to be far from μ\mu. It does not say a particular trajectory, as nn grows, eventually stays near μ\mu forever: each nn might have different bad trajectories. The strong law of large numbers (SLLN) asserts the latter: Xˉn→μ\bar X_n \to \mu almost surely. The figure showed the difference between P(∣Xˉn−μ∣>ε)\Pr(\abs{\bar X_n - \mu} > \varepsilon) and P(sup⁡m≥n∣Xˉm−μ∣>ε)\Pr(\sup_{m \ge n}\abs{\bar X_m - \mu} > \varepsilon).

With a fourth moment: Borel-Cantelli

The shortest proof uses stronger assumptions and teaches the mechanism. First calculate a moment of the sum.

Sn4=∑i,j,k,l≤nXiXjXkXl,E[Xi]=0S_n^4 = \sum_{i,j,k,l \le n} X_iX_jX_kX_l, \qquad \E[X_i] = 0
Assume centered variables, E[Xi]=0\E[X_i] = 0, and E[Xi4]=m4<∞\E[X_i^4] = m_4 < \infty (hence σ2=E[Xi2]<∞\sigma^2 = \E[X_i^2] < \infty). The XiX_i are independent and identically distributed.
1/5

Order of magnitude matters more than the constant: E[Sn4]\E[S_n^4] grows as n2n^2, not n4n^4. Almost all combinations of indices cancel. The strong law follows.

Proof

Without loss of generality μ=0\mu = 0 (replace XiX_i by Xi−μX_i - \mu, which still has finite fourth moment because (a−b)4≤8(a4+b4)(a - b)^4 \le 8(a^4 + b^4)). By Markov’s inequality applied to Sn4S_n^4 and the preceding bound, for each ε>0\varepsilon > 0,

P(∣Xˉn∣>ε)=P(Sn4>(nε)4)≤E[Sn4]n4ε4≤3 m4ε4⋅1n2.\Pr\big(\abs{\bar X_n} > \varepsilon\big) = \Pr\big(S_n^4 > (n\varepsilon)^4\big) \le \frac{\E[S_n^4]}{n^4\varepsilon^4} \le \frac{3\,m_4}{\varepsilon^4}\cdot\frac{1}{n^2}.

The series ∑nn−2\sum_n n^{-2} converges, so ∑nP(∣Xˉn∣>ε)<∞\sum_n \Pr(\abs{\bar X_n} > \varepsilon) < \infty. By the first Borel-Cantelli lemma, P(∣Xˉn∣>ε infinitas veces)=0\Pr(\abs{\bar X_n} > \varepsilon \text{ infinitas veces}) = 0: almost surely ∣Xˉn∣≤ε\abs{\bar X_n} \le \varepsilon except for finitely many nn. Take ε=1/j\varepsilon = 1/j and the countable union of null events {lim sup⁡∣Xˉn∣>1/j}\{\limsup\abs{\bar X_n} > 1/j\}: almost surely lim sup⁡∣Xˉn∣≤1/j\limsup\abs{\bar X_n} \le 1/j for every jj, that is, Xˉn→0\bar X_n \to 0.

∎

Notice why this works here but not with Chebyshev: Chebyshev’s bound σ2/(nε2)\sigma^2/(n\varepsilon^2) forms a harmonic series and diverges, so Borel-Cantelli says nothing. The strong law needs tails P(∣Xˉn−μ∣>ε)\Pr(\abs{\bar X_n - \mu} > \varepsilon) summable in nn, or a trick avoiding that requirement. With a fourth moment the tail falls as n−2n^{-2}, which suffices. Etemadi supplies the general trick.

With only finite mean: Etemadi

The theorem used in practice requires neither a fourth moment nor even variance.

Proof

Forward direction (Etemadi). Applying the argument separately to X+X^+ and X−X^- (still identically distributed and pairwise independent), it suffices to assume Xi≥0X_i \ge 0.

Step 1: truncate. Let Yk=Xk1[Xk≤k]Y_k = X_k\ind[X_k \le k] and Tn=Y1+⋯+YnT_n = Y_1 + \dots + Y_n. Since ∑kP(Xk≠Yk)=∑kP(X1>k)≤∫0∞P(X1>t) ⁣dt=E[X1]<∞\sum_k \Pr(X_k \ne Y_k) = \sum_k \Pr(X_1 > k) \le \int_0^\infty \Pr(X_1 > t)\dd t = \E[X_1] < \infty, Borel-Cantelli gives that almost surely Xk=YkX_k = Y_k except for finitely many kk; thus Sn/n−Tn/n→0S_n/n - T_n/n \to 0. It suffices to show Tn/n→μT_n/n \to \mu.

Step 2: means. By monotone convergence, E[Yk]=E[X11[X1≤k]]↑μ\E[Y_k] = \E[X_1\ind[X_1 \le k]] \uparrow \mu, and the Cesàro mean of a convergent sequence converges: E[Tn]/n→μ\E[T_n]/n \to \mu.

Step 3: a geometric subsequence. Fix α>1\alpha > 1 and kn=⌊αn⌋k_n = \lfloor\alpha^n\rfloor. The variance of a sum of pairwise independent variables is the sum of variances, so by Chebyshev, for ε>0\varepsilon > 0,

∑nP(∣Tkn−ETkn∣>εkn)≤1ε2∑n1kn2∑k≤knVar⁡(Yk)=1ε2∑kVar⁡(Yk)∑n: kn≥k1kn2.\sum_n \Pr\big(\abs{T_{k_n} - \E T_{k_n}} > \varepsilon k_n\big) \le \frac{1}{\varepsilon^2}\sum_n\frac{1}{k_n^2}\sum_{k \le k_n}\Var(Y_k) = \frac{1}{\varepsilon^2}\sum_{k}\Var(Y_k)\sum_{n:\,k_n \ge k}\frac{1}{k_n^2}.

Since kn≥αn/2k_n \ge \alpha^n/2 and kn≥kk_n \ge k implies αn≥k\alpha^n \ge k, the inner sum is at most 4∑n: αn≥kα−2n≤41−α−2 k−24\sum_{n:\,\alpha^n \ge k}\alpha^{-2n} \le \frac{4}{1 - \alpha^{-2}}\,k^{-2}. It remains to bound ∑kVar⁡(Yk)/k2≤∑kE[Yk2]/k2=E[X12∑k≥max⁡(1,X1)k−2]\sum_k \Var(Y_k)/k^2 \le \sum_k \E[Y_k^2]/k^2 = \E\big[X_1^2\sum_{k \ge \max(1, X_1)}k^{-2}\big]. For x>0x > 0, ∑k≥max⁡(1,x)k−2≤2/x\sum_{k \ge \max(1, x)}k^{-2} \le 2/x, so that quantity is at most 2 E[X1]<∞2\,\E[X_1] < \infty. By Borel-Cantelli (taking ε=1/j\varepsilon = 1/j), (Tkn−ETkn)/kn→0(T_{k_n} - \E T_{k_n})/k_n \to 0 almost surely; with step 2, Tkn/kn→μT_{k_n}/k_n \to \mu almost surely.

Step 4: monotonicity. Since Yk≥0Y_k \ge 0, TmT_m increases in mm. For kn≤m<kn+1k_n \le m < k_{n+1},

knkn+1⋅Tknkn  ≤  Tmm  ≤  kn+1kn⋅Tkn+1kn+1,\frac{k_n}{k_{n+1}}\cdot\frac{T_{k_n}}{k_n} \;\le\; \frac{T_m}{m} \;\le\; \frac{k_{n+1}}{k_n}\cdot\frac{T_{k_{n+1}}}{k_{n+1}},

and kn+1/kn→αk_{n+1}/k_n \to \alpha. Thus μ/α≤lim inf⁡Tm/m≤lim sup⁡Tm/m≤αμ\mu/\alpha \le \liminf T_m/m \le \limsup T_m/m \le \alpha\mu almost surely. Taking α=1+1/j\alpha = 1 + 1/j and the countable intersection yields Tm/m→μT_m/m \to \mu.

Converse. If Xˉn→L∈R\bar X_n \to L \in \R on a positive-probability event AA, then on AA, Xn/n=Xˉn−n−1nXˉn−1→L−L=0X_n/n = \bar X_n - \frac{n-1}{n}\bar X_{n-1} \to L - L = 0, so ∣Xn∣>n\abs{X_n} > n occurs only finitely often. But E∣X1∣≤1+∑n≥1P(∣X1∣>n)\E\abs{X_1} \le 1 + \sum_{n \ge 1}\Pr(\abs{X_1} > n), and if E∣X1∣=∞\E\abs{X_1} = \infty the series ∑nP(∣Xn∣>n)\sum_n\Pr(\abs{X_n} > n) diverges: by the second Borel-Cantelli lemma (the XnX_n are independent), ∣Xn∣>n\abs{X_n} > n occurs infinitely often almost surely. Contradiction; hence E∣X1∣<∞\E\abs{X_1} < \infty.

∎

Three comments. First, Etemadi proves the strong law with only pairwise independence, much weaker than joint independence, in less space than Kolmogorov’s classical proof. Second, the converse says finite expectation is not a technical convenience: it is exactly the condition for an iid average to converge almost surely to a number. Third, the strong law implies the weak law (almost-sure convergence implies convergence in probability), but not conversely: the next example and St Petersburg paradox show this.

Kolmogorov’s zero-one law

The previous two theorems say when the average converges. Could it do so with probability 1/21/2, or converge to a random limit? Not for independent sequences, due to a very general symmetry property.

Tail events include “series ∑Xn\sum X_n converges”, “Xn∈BX_n \in B infinitely often”, and “Xˉn\bar X_n converges”. The last is not obvious. For each fixed kk, Xˉn=Sk/n+1n∑i=k+1nXi\bar X_n = S_k/n + \frac{1}{n}\sum_{i=k+1}^{n}X_i and Sk/n→0S_k/n \to 0, so Xˉn\bar X_n and 1n∑i=k+1nXi\frac{1}{n}\sum_{i=k+1}^{n}X_i have the same lim sup⁡\limsup and lim inf⁡\liminf. The second is measurable with respect to σ(Xk+1,… )\sigma(X_{k+1}, \dots) for every kk, hence lim sup⁡Xˉn\limsup\bar X_n and lim inf⁡Xˉn\liminf\bar X_n are T\mathcal{T}-measurable. These events and variables obey a sharp dichotomy.

Proof

Let Fn=σ(X1,…,Xn)\mathcal{F}_n = \sigma(X_1, \dots, X_n) and Gn=σ(Xn+1,Xn+2,… )\mathcal{G}_n = \sigma(X_{n+1}, X_{n+2}, \dots). By independence of the family, Fn\mathcal{F}_n and Gn\mathcal{G}_n are independent (the π-λ theorem groups independent variables into independent σ-algebras). Since T⊆Gn\mathcal{T} \subseteq \mathcal{G}_n, every A∈TA \in \mathcal{T} is independent of Fn\mathcal{F}_n for every nn. Thus AA is independent of the family ⋃nFn\bigcup_n\mathcal{F}_n, a π-system (the Fn\mathcal{F}_n increase) generating F∞=σ(X1,X2,… )\mathcal{F}_\infty = \sigma(X_1, X_2, \dots); by π-λ, AA is independent of all F∞\mathcal{F}_\infty. But A∈T⊆F∞A \in \mathcal{T} \subseteq \mathcal{F}_\infty, so AA is independent of itself: P(A)=P(A∩A)=P(A)2\Pr(A) = \Pr(A \cap A) = \Pr(A)^2, and P(A)∈{0,1}\Pr(A) \in \{0, 1\}.

For an ZZ T\mathcal{T}-measurable variable, each {Z≤q}\{Z \le q\} belongs to T\mathcal{T} and has probability 00 or 11. Function q↦P(Z≤q)q \mapsto \Pr(Z \le q) is increasing and takes only those values, so it jumps from 00 to 11 at some point c∈[−∞,∞]c \in [-\infty, \infty], and Z=cZ = c almost surely.

∎

Applied to lim sup⁡Xˉn\limsup\bar X_n and lim inf⁡Xˉn\liminf\bar X_n, the zero-one law says both are almost-sure constants. Therefore the average of independent variables either converges almost surely to a constant or almost surely does not converge; it never converges with intermediate probability or to a random value. Together with Etemadi’s converse, iid variables have a complete dichotomy:

ConditionBehavior of Xˉn\bar X_n
E∣X1∣<∞\E\abs{X_1} < \inftyconverges almost surely to constant E[X1]\E[X_1]
E∣X1∣=∞\E\abs{X_1} = \inftyalmost surely does not converge to any finite limit

There is no middle ground. This depends on independence: without it, a single random ZZ and sequence Xi=ZX_i = Z for every ii yield Xˉn=Z\bar X_n = Z, converging to a random limit. The final section returns to this case.

When it fails: heavy tails

Etemadi’s converse says that without finite expectation there is no law of large numbers. Consider three concrete failures, from bluntest to subtlest.

Cauchy: averaging improves nothing

The standard Cauchy law has density 1π(1+x2)\frac{1}{\pi(1 + x^2)} and characteristic function φ(t)=e−∣t∣\varphi(t) = e^{-\abs{t}} (the characteristic function of lesson 13). For iid Cauchy XiX_i, the mean’s characteristic function is

φXˉn(t)=φSn(t/n)=φ(t/n)n=(e−∣t∣/n)n=e−∣t∣,\varphi_{\bar X_n}(t) = \varphi_{S_n}(t/n) = \varphi(t/n)^n = \big(e^{-\abs{t}/n}\big)^n = e^{-\abs{t}},

the same. By uniqueness, Xˉn\bar X_n is Cauchy for every nn: averaging a thousand observations does not narrow its distribution at all. If Xˉn→c\bar X_n \to c in probability, it would converge in distribution to constant cc, which a Cauchy is not. This is what the figure showed. The mean of Cauchy data poorly estimates the center; the sample median does converge.

Pareto: the exponent decides

The Pareto law of index α>0\alpha > 0 has P(X>x)=x−α\Pr(X > x) = x^{-\alpha} for x≥1x \ge 1. Its expectation is α/(α−1)\alpha/(\alpha - 1) if α>1\alpha > 1 and infinite if α≤1\alpha \le 1; variance is finite only if α>2\alpha > 2. It is the canonical heavy-tail model and divides behaviors as follows.

Proof

For each M>0M > 0, bounded variables Xi∧MX_i \wedge M are iid with finite expectation E[X1∧M]\E[X_1 \wedge M], and by the strong law 1n∑i(Xi∧M)→E[X1∧M]\frac{1}{n}\sum_i (X_i \wedge M) \to \E[X_1 \wedge M] almost surely. Since Xˉn≥1n∑i(Xi∧M)\bar X_n \ge \frac{1}{n}\sum_i (X_i \wedge M), it follows lim inf⁡Xˉn≥E[X1∧M]\liminf\bar X_n \ge \E[X_1 \wedge M] almost surely. By monotone convergence E[X1∧M]↑E[X1]=∞\E[X_1 \wedge M] \uparrow \E[X_1] = \infty as M→∞M \to \infty (taking integer MM and the countable intersection).

∎

The strong law is a proof tool here, not merely a theorem. At what rate? For α∈(0,2)\alpha \in (0, 2) the sum (centered if α>1\alpha > 1) grows as n1/αn^{1/\alpha} (the stable-law regime in the CLT lesson), and the average as n1/α−1n^{1/\alpha - 1}. For α=0.8\alpha = 0.8 this exponent is +0.25+0.25 (growing); for α=1.5\alpha = 1.5 it is −1/3-1/3 (error decreases, but slower than n−1/2n^{-1/2}); approaching 11 from the right makes convergence slower, with exponent 1/α−11/\alpha - 1 tending to 00. This answers the third motivating question: the law of large numbers has no universal rate. With pp finite moments, 1≤p<21 \le p < 2, the Marcinkiewicz-Zygmund law guarantees Xˉn−μ=o(n1/p−1)\bar X_n - \mu = o(n^{1/p - 1}) almost surely; with p=2p = 2 one recovers order n−1/2n^{-1/2} (apart from factor 2ln⁡ln⁡n\sqrt{2\ln\ln n}, by the iterated logarithm law), while E∣X∣<∞\E\abs{X} < \infty alone yields only convergence.

The table summarizes these cases, with the figure’s estimated slope:

LawE[X]\E[X]Var⁡(X)\Var(X)Weak lawStrong lawTypical size of ∣Xˉn−μ∣\abs{\bar X_n - \mu}
Bernoulli, exponentialfinitefiniteyesyesn−1/2n^{-1/2}
Student tt with 2 degrees of freedom00infiniteyesyesslightly slower than n−1/2n^{-1/2}
Pareto α=1.5\alpha = 1.533infiniteyesyesn−1/3n^{-1/3}
Pareto α=0.8\alpha = 0.8infiniteinfinitenono: Xˉn→+∞\bar X_n \to +\inftygrows as n0.25n^{0.25}
Cauchydoes not existinfinitenonoconstant: Xˉn=dX1\bar X_n \overset{d}{=} X_1

St Petersburg: a game with infinite value and finite price

In the St Petersburg game a fair coin is tossed until heads appears. If this occurs at toss KK (with P(K=k)=2−k\Pr(K = k) = 2^{-k}), the player receives 2K2^K euros. Each level kk contributes exactly 2k⋅2−k=12^k\cdot 2^{-k} = 1 to expectation, and there are infinitely many: E[2K]=∞\E[2^K] = \infty. The paradox is that nobody would pay a fortune to play. What does the law of large numbers, which does not apply, say?

InteractiveThe St Petersburg paradox
Running mean winnings per game, Sn/nS_n / n, for each player
  • highlighted player
  • other players
  • median (thick line)
  • log⁡2n\log_2 n
Contribution to the sum by each level kk (highlighted player, n=10000n = 10000): number of games with K=kK = k times prize, divided by nn
1 per level
  • 2k≤n2^k \le n: contributes ≈1\approx 1
  • 2k>n2^k > n: arrives in jumps
12
Games per player
10000
Highlighted player's mean winnings16.18
log⁡2n\log_2 n13.29
Median across players19.69
Expectation E[2K]\E[2^K]∞
Highlighted player's largest prize32768
Share of that prize in the sum20.3 %
Each trajectory is a player's mean winnings. Without a bankroll limit it does not stabilize: it grows like log⁡2n\log_2 n (dashed line), with sudden jumps. Right: each level kk contributes an average of 11 per game while 2k≤n2^k \le n (blue bars); above log⁡2n\log_2 n levels appear only singly and enormous (red). Cap the bankroll at 2M2^M: the prize becomes min⁡(2K,2M)\min(2^K, 2^M), expectation is M+1M + 1, and the law of large numbers finally holds. With M=30M = 30, observing convergence takes far more than 10510^5 games.

What you should have seen:

  • Mean winnings grow without bound, as log⁡2n\log_2 n. About log⁡2n\log_2 n levels are already “filled” (those with prizes below nn), each contributing about 11 per game. Higher levels are so rare they appear in jumps. With n=104n = 10^4 typical mean winnings are around 1616, or log⁡2104=13.3\log_2 10^4 = 13.3 plus a constant near 33.
  • One prize can make up most of the sum. Its fraction of the sum jumps when the highlighted player has an exceptional game.
  • With a finite bankroll, things return to normal. Bounded prize min⁡(2K,2M)\min(2^K, 2^M) has expectation M+1M + 1: each level k≤Mk \le M contributes 11, and levels k>Mk > M jointly contribute 2MP(K>M)=12^M\Pr(K > M) = 1. With M=10M = 10 fair value is 1111 and the mean converges to it; a real casino’s finite bankroll is the paradox’s practical solution.
Proof

For part 2. For x≥1x \ge 1, P(X1>x)=P(K>log⁡2x)=2−⌊log⁡2x⌋≥1/x\Pr(X_1 > x) = \Pr(K > \log_2 x) = 2^{-\lfloor\log_2 x\rfloor} \ge 1/x. For each c>0c > 0, ∑nP(Xn>c nlog⁡2n)≥∑n1c nlog⁡2n=∞\sum_n\Pr(X_n > c\,n\log_2 n) \ge \sum_n\frac{1}{c\,n\log_2 n} = \infty. As the XnX_n are independent, the second Borel-Cantelli lemma says Xn>c nlog⁡2nX_n > c\,n\log_2 n occurs infinitely often almost surely. Since Xi≥0X_i \ge 0, Sn≥XnS_n \ge X_n, so lim sup⁡Sn/(nlog⁡2n)≥c\limsup S_n/(n\log_2 n) \ge c. With c∈Nc \in \mathbb{N} and the countable intersection, lim sup⁡\limsup is infinite.

∎

Part 1 is quantitative: the fair price for nn games is ≈log⁡2n\approx\log_2 n per game. Part 2 explains the red bars: with bn=nlog⁡2nb_n = n\log_2 n, ratio Sn/bnS_n/b_n does not behave almost surely like a constant. Better normalization does not solve this: Chow and Robbins (1961) showed that for iid nonnegative infinite-mean variables, no deterministic sequence bnb_n achieves Sn/bn→1S_n/b_n \to 1 almost surely.

Glivenko-Cantelli: the strong law uniformly

So far the law estimates one number, an expectation. What if we want an entire distribution? The cumulative distribution function F(x)=P(X≤x)F(x) = \Pr(X \le x) is infinite-dimensional, and an indicator’s expectation estimates it pointwise.

For each fixed xx, Fn(x)F_n(x) averages variables 1[Xi≤x]\ind[X_i \le x], iid Bernoulli with parameter F(x)F(x). The strong law gives Fn(x)→F(x)F_n(x) \to F(x) almost surely for each xx. But for each xx is weak: an uncountable union of null events can have positive probability, and we do not even know DnD_n is a random variable. (It is: right continuity makes the supremum over R\R equal the supremum over countable Q\mathbb{Q}.) Glivenko-Cantelli moves from pointwise to all points at once.

Proof

Fix ε>0\varepsilon > 0 and choose mm with 1/m<ε1/m < \varepsilon. Let t0=−∞t_0 = -\infty, tj=inf⁡{y:F(y)≥j/m}t_j = \inf\{y : F(y) \ge j/m\} for j=1,…,m−1j = 1, \dots, m-1 and tm=+∞t_m = +\infty, with convention F(t0)=0F(t_0) = 0, F(tm−)=1F(t_m^-) = 1. By right continuity F(tj)≥j/mF(t_j) \ge j/m, and by definition of infimum F(tj−)≤j/mF(t_j^-) \le j/m. Thus F(tj−)−F(tj−1)≤1/m<εF(t_j^-) - F(t_{j-1}) \le 1/m < \varepsilon for every jj.

By the strong law applied to indicators 1[Xi≤tj]\ind[X_i \le t_j] and 1[Xi<tj]\ind[X_i < t_j] (there are only 2(m−1)2(m-1)), almost surely

ηn:=max⁡jmax⁡(∣Fn(tj)−F(tj)∣, ∣Fn(tj−)−F(tj−)∣)⟶0.\eta_n := \max_j\max\big(\abs{F_n(t_j) - F(t_j)},\ \abs{F_n(t_j^-) - F(t_j^-)}\big) \longrightarrow 0.

Let x∈[tj−1,tj)x \in [t_{j-1}, t_j). By monotonicity of FnF_n and FF,

Fn(x)≤Fn(tj−)≤F(tj−)+ηn≤F(tj−1)+ε+ηn≤F(x)+ε+ηn,F_n(x) \le F_n(t_j^-) \le F(t_j^-) + \eta_n \le F(t_{j-1}) + \varepsilon + \eta_n \le F(x) + \varepsilon + \eta_n,Fn(x)≥Fn(tj−1)≥F(tj−1)−ηn≥F(tj−)−ε−ηn≥F(x)−ε−ηn.F_n(x) \ge F_n(t_{j-1}) \ge F(t_{j-1}) - \eta_n \ge F(t_j^-) - \varepsilon - \eta_n \ge F(x) - \varepsilon - \eta_n.

Thus Dn≤ε+ηnD_n \le \varepsilon + \eta_n and lim sup⁡Dn≤ε\limsup D_n \le \varepsilon almost surely. With ε=1/r\varepsilon = 1/r, r=1,2,…r = 1, 2, \dots and the countable intersection, Dn→0D_n \to 0 almost surely.

∎

Notice the result. The strong law for average Xˉn\bar X_n fails for Cauchy, but Glivenko-Cantelli still applies: indicators are bounded and have no moment problem. Estimating a distribution is much more robust than estimating its mean. This is also the first example of uniform convergence over a class of functions (here indicators 1[⋅≤x]\ind[\cdot \le x]); learning theory generalizes it to classes of finite Vapnik-Chervonenkis dimension.

DKW: the first nonasymptotic uniform bound

Glivenko-Cantelli gives no rate; a statistician needs a guaranteed band width around FnF_n for given nn. The answer is the most-used result of one-dimensional empirical process theory.

Dvoretzky, Kiefer and Wolfowitz proved it in 1956 with an unspecified constant in the factor before the exponential; Massart (1990) proved 22 is valid and optimal. The delicate proof is outside this lesson; we use the result. To understand its contribution, consider what available tools yield.

Three consequences are used constantly:

  • Confidence band. With εn(δ)=ln⁡(2/δ)/(2n)\varepsilon_n(\delta) = \sqrt{\ln(2/\delta)/(2n)}, setting 2e−2nε2=δ2e^{-2n\varepsilon^2} = \delta equal gives P(Fn(x)−εn≤F(x)≤Fn(x)+εn para todo x)≥1−δ\Pr\big(F_n(x) - \varepsilon_n \le F(x) \le F_n(x) + \varepsilon_n \text{ para todo } x\big) \ge 1 - \delta. This band is simultaneous and assumes nothing about FF.
  • Sample size. To obtain Dn≤εD_n \le \varepsilon with probability at least 1−δ1 - \delta, n≥ln⁡(2/δ)/(2ε2)n \ge \ln(2/\delta)/(2\varepsilon^2) suffices. For example, with ε=0.05\varepsilon = 0.05 and δ=0.01\delta = 0.01, n≥ln⁡(200)/0.005=1059.7n \ge \ln(200)/0.005 = 1059.7: 10601060 observations suffice.
  • An almost-sure rate for Glivenko-Cantelli. With εn=ln⁡n/n\varepsilon_n = \sqrt{\ln n/n}, ∑n2e−2ln⁡n=∑n2/n2<∞\sum_n 2e^{-2\ln n} = \sum_n 2/n^2 < \infty and, by Borel-Cantelli, almost surely Dn≤ln⁡n/nD_n \le \sqrt{\ln n/n} except for finitely many nn. The true order, given by Chung and Smirnov’s iterated logarithm law, is ln⁡ln⁡n/n\sqrt{\ln\ln n/n}; DKW loses very little.
InteractiveEmpirical distribution and its DKW band
FnF_n versus FF, with the DKW band and supremum distance
  • true FF
  • empirical FnF_n
  • band Fn±εnF_n \pm \varepsilon_n
  • DnD_n
Tail of DnD_n: P(Dn>t)\Pr(D_n > t) in 300 samples versus bound 2e−2nt22e^{-2nt^2}
ε = 0.607δ = 0.05
  • simulated P(Dn>t)\Pr(D_n > t)
  • DKW bound
  • sample DnD_n
Band level δ\delta
n = 5
nn5
Half-width εn=ln⁡(2/δ)/(2n)\varepsilon_n = \sqrt{\ln(2/\delta)/(2n)}0.6074
Dn=sup⁡x∣Fn(x)−F(x)∣D_n = \sup_x |F_n(x) - F(x)| for this sample0.2273
Does FF fit in the band?yes
Coverage across 300 samples (guarantee ≥0.95\ge 0.95)96.0 %
n Dn\sqrt{n}\,D_n0.508
Press play and watch FnF_n (blue staircase) close in on FF (thick line in text color) as observations are added; the red line marks where DnD_n is attained. The DKW band (blue shading) contains FF with probability at least 1−δ1 - \delta. Change the distribution: the sample changes but DnD_n does not, because it depends only on the uniform F(Xi)F(X_i). Right: the simulated DnD_n tail (blue) almost touches bound 2e−2nt22e^{-2nt^2} (orange), nearly exact in the tails. With δ=0.5\delta = 0.5 coverage exceeds the guarantee; with δ=0.01\delta = 0.01 it nearly matches it.

What you should have seen:

  • DnD_n depends on the sample and nn, not FF. For continuous FF, F(Xi)F(X_i) are uniform on [0,1][0, 1] (the probability integral transform) and DnD_n is the same functional of these uniforms. Thus DKW and its band work for any FF, including Cauchy; with atoms, DnD_n is stochastically smaller and the inequality still holds.
  • The band narrows as 1/n1/\sqrt{n}, like everything in this lesson. Reading n Dn\sqrt{n}\,D_n stays of order 11 for all nn, underlying the Kolmogorov-Smirnov test.
  • The bound is nearly exact. With n=1000n = 1000 simulated coverage is about 90 %90\,\% for δ=0.1\delta = 0.1, 95 %95\,\% for δ=0.05\delta = 0.05 and 99 %99\,\% for δ=0.01\delta = 0.01: as promised up to simulation error. The limit of P(nDn>λ)\Pr(\sqrt{n}D_n > \lambda) is the Kolmogorov series 2∑k≥1(−1)k−1e−2k2λ22\sum_{k \ge 1}(-1)^{k-1}e^{-2k^2\lambda^2}, whose first term is exactly the DKW bound. Only when δ\delta is large is the tail thinner: with δ=0.5\delta = 0.5 exact coverage is 51.6 %51.6\,\% for n=1000n = 1000 and slightly higher for small nn (around 5454 or 55 %55\,\% with n=20n = 20 or 100100, as in the code cell).

Beyond iid: a preview

Everything above assumes independence. Time series, Markov-chain data and losses from learning processes violate it. Three useful facts, without full proofs:

Vanishing correlation. The finite-variance weak-law proof used only uncorrelatedness. It extends to stationary processes with autocovariance γ(k)=Cov⁡(X0,Xk)→0\gamma(k) = \Cov(X_0, X_k) \to 0: then Var⁡(Xˉn)=1n∑∣k∣<n(1−∣k∣n)γ(k)≤1n∑∣k∣<n∣γ(k)∣→0\Var(\bar X_n) = \frac{1}{n}\sum_{\abs{k} < n}(1 - \frac{\abs{k}}{n})\gamma(k) \le \frac{1}{n}\sum_{\abs{k} < n}\abs{\gamma(k)} \to 0 (the average of a sequence tending to 00 tends to 00), and Chebyshev gives Xˉn→μ\bar X_n \to \mu in probability. What is lost is effective sample size: for an autoregressive process with coefficient ϕ\phi, Var⁡(Xˉn)≈σX2n⋅1+ϕ1−ϕ\Var(\bar X_n) \approx \frac{\sigma_X^2}{n}\cdot\frac{1+\phi}{1-\phi}, so nn observations with ϕ=0.9\phi = 0.9 are worth about n/19n/19 independent ones.

Ergodic averages. Birkhoff’s ergodic theorem generalizes the strong law to stationary ergodic processes: time averages converge almost surely to expectation. “Ergodic” excludes the earlier counterexample Xi=ZX_i = Z for all ii: here the tail is nontrivial, the zero-one law fails and the time average converges to a random variable, not ensemble expectation E[Z]\E[Z]. In practice an irreducible positive-recurrent Markov chain is ergodic; the stochastic-processes module develops this and justifies MCMC.

Ensemble versus time average. The strong law applied to logarithms prevents confusion. Consider capital multiplied at each step by 1.51.5 or 0.60.6 with equal probability. Expected factor per step is 0.5(1.5)+0.5(0.6)=1.050.5(1.5) + 0.5(0.6) = 1.05 and E[W100]=1.05100≈131.5\E[W_{100}] = 1.05^{100} \approx 131.5. But the strong law applied to the factor’s ln⁡\ln yields 1nln⁡Wn→0.5ln⁡1.5+0.5ln⁡0.6=−0.0527\frac{1}{n}\ln W_n \to 0.5\ln 1.5 + 0.5\ln 0.6 = -0.0527 almost surely: the typical trajectory decays exponentially. With n=100n = 100, P(W100<1)=P(Bin(100,12)≤55)≈0.864\Pr(W_{100} < 1) = \Pr(\text{Bin}(100, \tfrac12) \le 55) \approx 0.864. A handful of extremely lucky trajectories sustain expectation, and no individual lives in the ensemble average. The multiplicative-processes module develops this.

Implementation from scratch

We will build three things with NumPy: strong-law simulations for several distributions (checking the fourth moment and rate slope), a heavy-tail diagnostic examining moving-mean instability, and the empirical distribution function with its DKW band and simulated coverage.

[ ]Fourth moment of the sum and strong-law rateBrowser
import numpy as np
from scipy.stats import binom

# 1) E[S^4] = n m4 + 3 n (n-1) σ⁴, exacto para Bernoulli(p) centrada (no hace falta simular)
p = 0.3
for n in (5, 50, 500):
    k = np.arange(n + 1)
    exacto = (binom.pmf(k, n, p) * (k - n * p) ** 4).sum()
    s2 = p * (1 - p)
    m4 = p * (1 - p) * (1 - 3 * p * (1 - p))        # momento central de orden 4 de una Bernoulli
    formula = n * m4 + 3 * n * (n - 1) * s2**2
    print(f"n={n:4d}  E[S^4] exacto={exacto:12.4f}  fórmula={formula:12.4f}  cota 3 n² m4={3*n*n*m4:12.2f}")

# 2) Velocidad: pendiente log-log del error mediano de las medias acumuladas
rng = np.random.default_rng(0)
SAMPLERS = {
    "Bernoulli(0.3)": (lambda size: (rng.random(size) < 0.3).astype(float), 0.3),
    "Exponencial(1)": (lambda size: rng.exponential(1.0, size), 1.0),
    "Pareto(1.5)":    (lambda size: rng.pareto(1.5, size) + 1.0, 3.0),
    "Pareto(0.8)":    (lambda size: rng.pareto(0.8, size) + 1.0, None),
    "Cauchy":         (lambda size: rng.standard_cauchy(size), None),
}
R, N = 100, 10_000
ns = np.unique(np.logspace(1.5, 4, 20).astype(int))
print()
for name, (draw, mu) in SAMPLERS.items():
    x = draw((R, N))
    medias = np.cumsum(x, axis=1)[:, ns - 1] / ns          # X̄_n de cada trayectoria
    centro = 0.0 if mu is None else mu                      # si no hay media, se mide |X̄_n|
    err = np.median(np.abs(medias - centro), axis=0)
    pend = np.polyfit(np.log(ns), np.log(err), 1)[0]
    print(f"{name:15s} error mediano en n=10⁴: {err[-1]:10.4f}   pendiente log-log: {pend:+.2f}")

The first part confirms the fourth-moment formula with exact arithmetic (the binomial permits it), and bound 3n2m43n^2m_4 is loose but of the right order. The second reproduces the figure: −0.5-0.5 for finite-variance laws, about −1/3-1/3 for Pareto 1.51.5, +0.3+0.3 for Pareto 0.80.8 (the theoretical limit is 0.250.25, and at n=104n = 10^4 the prior regime is still visible), and 00 for Cauchy.

Now a practical diagnostic. Given a column to average (latencies, losses, rewards), how can you suspect an unreliable mean? Three cheap signals: the largest value’s share of the sum, moving-mean drift and Hill’s tail-index estimator.

[ ]Detecting heavy tails: maximum share, mean drift and Hill estimatorBrowser
import numpy as np

def peso_maximo(x):
    """Fracción de Σ|x_i| que aporta el mayor |x_i|: si no es despreciable, la media no se ha estabilizado."""
    a = np.abs(x)
    return a.max() / a.sum()

def deriva(x, tramos=10):
    """Mayor cambio de la media acumulada entre puntos de control, en unidades de la mediana de |x|."""
    n = len(x)
    m = np.cumsum(x) / np.arange(1, n + 1)
    pts = m[np.linspace(n // tramos, n, tramos).astype(int) - 1]
    return np.abs(np.diff(pts)).max() / np.median(np.abs(x))

def hill(x, k):
    """Estimador de Hill del índice de cola α con los k mayores |x|, y su error estándar aproximado α/√k."""
    a = np.sort(np.abs(x))[::-1]
    alfa = 1.0 / np.mean(np.log(a[:k] / a[k]))
    return alfa, alfa / np.sqrt(k)

def veredicto(alfa, se, umbral):
    if alfa + 2 * se < umbral:
        return "no"
    if alfa - 2 * se > umbral:
        return "sí"
    return "dudoso"

rng = np.random.default_rng(4)
n, k = 100_000, 500
muestras = {
    "Normal": rng.standard_normal(n),
    "Exponencial": rng.exponential(1.0, n),
    "t de Student (2 g.l.)": rng.standard_t(2, n),
    "Pareto(1.5)": rng.pareto(1.5, n) + 1,
    "Pareto(0.8)": rng.pareto(0.8, n) + 1,
    "Cauchy": rng.standard_cauchy(n),
}
print(f"{'ley':22s} {'mayor/suma':>10s} {'deriva':>8s} {'α̂ de Hill':>16s}  ¿media finita?  ¿varianza finita?")
for nombre, x in muestras.items():
    alfa, se = hill(x, k)
    print(f"{nombre:22s} {100*peso_maximo(x):9.3f}% {deriva(x):8.3f} {alfa:9.2f} ± {2*se:4.2f}  {veredicto(alfa, se, 1):>13s}  {veredicto(alfa, se, 2):>15s}")

Read this table carefully, not blindly. Light-tailed laws have maximum share of order 0.01 %0.01\,\% and negligible drift; Pareto 0.80.8 and Cauchy reveal themselves through huge drift and a maximum weighing between 44 and 14 %14\,\% of the entire sum. Hill correctly classifies Pareto 0.80.8 (infinite mean) and Pareto 1.51.5 (finite mean, infinite variance), and honestly recognizes it cannot distinguish Cauchy (α=1\alpha = 1) from a finite-mean law or t2t_2 (α=2\alpha = 2) from finite variance: α\alpha confidence intervals touch the threshold. Another seed changes the numbers (especially Pareto’s highly variable maximum share); that variability is the information.

Finally, the empirical distribution, DKW band and coverage check:

[ ]ECDF, DKW band and simulated coverage from scratchBrowser
import numpy as np
from scipy import stats

def ecdf(x):
    """Devuelve F_n como función: F_n(t) = #{x_i <= t} / n, vectorizada en t."""
    xs = np.sort(np.asarray(x, dtype=float))
    n = len(xs)
    return lambda t: np.searchsorted(xs, t, side="right") / n

def dkw_eps(n, delta):
    return np.sqrt(np.log(2 / delta) / (2 * n))

def dkw_band(x, delta):
    """Banda de confianza 1 − δ para F: devuelve t ↦ (inferior, superior), recortada a [0, 1]."""
    F, eps = ecdf(x), dkw_eps(len(x), delta)
    return lambda t: (np.clip(F(t) - eps, 0, 1), np.clip(F(t) + eps, 0, 1))

def distancia_ks(x, cdf):
    """D_n = sup_x |F_n(x) − F(x)|: basta mirar en los saltos, justo antes y justo después. x: (..., n)."""
    u = cdf(np.sort(x, axis=-1))
    n = u.shape[-1]
    i = np.arange(1, n + 1)
    return np.maximum((i / n - u).max(axis=-1), (u - (i - 1) / n).max(axis=-1))

rng = np.random.default_rng(0)
x = rng.standard_normal(200)
t = np.array([-1.0, 0.0, 1.0])
inf, sup = dkw_band(x, 0.05)(t)
print("F_n(-1, 0, 1)      =", ecdf(x)(t))
print("banda al 95 % en 0 =", (round(float(inf[1]), 3), round(float(sup[1]), 3)), " (F(0) = 0.5)")
print("D_n de la muestra  =", round(float(distancia_ks(x, stats.norm.cdf)), 4), " ε_n =", round(float(dkw_eps(200, 0.05)), 4))

# cobertura: la banda contiene a F entera si y solo si D_n <= ε_n
reps = 3000
print(f"\n{'n':>6s} {'δ':>6s} {'ε_n':>8s} {'cobertura simulada':>20s} {'garantía 1−δ':>14s}")
for n in (20, 100, 1000):
    D = distancia_ks(rng.standard_normal((reps, n)), stats.norm.cdf)
    for delta in (0.5, 0.1, 0.05, 0.01):
        eps = dkw_eps(n, delta)
        print(f"{n:6d} {delta:6.2f} {eps:8.4f} {100*(D <= eps).mean():19.1f}% {100*(1-delta):13.1f}%")

The identity justifying the loop matters: “FF fits in the band” is the same as Dn≤εnD_n \le \varepsilon_n, so coverage is P(Dn≤εn)\Pr(D_n \le \varepsilon_n) and simulated without drawing. Coverage is always near or above the promise, clearly loose only for δ=0.5\delta = 0.5. With 30003000 replicates Monte Carlo error is about ±0.4\pm 0.4 percentage points, so coverage slightly below the guarantee (94.8 %94.8\,\% for 95 %95\,\%) would be noise, not inequality failure.

With libraries

SciPy provides the exact distribution of DnD_n (scipy.stats.kstwo) and the Kolmogorov-Smirnov test (scipy.stats.kstest). This measures DKW slack, invisible in asymptotics.

[ ]Exact D_n tail versus DKW bound (SciPy)Browser
import numpy as np
from scipy import stats

n = 100
print(f"{'t':>6s} {'P(D_n>t) exacta':>16s} {'cota 2e^(-2nt²)':>16s} {'cociente':>9s}")
for t in (0.05, 0.08, 0.10, 0.12, 0.15, 0.20):
    exacta = stats.kstwo.sf(t, n)
    cota = 2 * np.exp(-2 * n * t * t)
    print(f"{t:6.2f} {exacta:16.5f} {cota:16.5f} {cota / exacta:9.2f}")

# el test de Kolmogorov-Smirnov es esta misma comparación: p-valor = P(D_n > D_observado)
rng = np.random.default_rng(1)
x = rng.standard_normal(n)
res = stats.kstest(x, "norm")
print(f"\nkstest: D_n = {res.statistic:.4f}, p-valor = {res.pvalue:.4f}  (= kstwo.sf: {stats.kstwo.sf(res.statistic, n):.4f})")

# n mínimo por DKW para una precisión dada, y n real según la ley exacta
eps, delta = 0.05, 0.05
n_dkw = int(np.ceil(np.log(2 / delta) / (2 * eps**2)))
n_ex = next(m for m in range(10, 2000) if stats.kstwo.sf(eps, m) <= delta)
print(f"\nPara ε = {eps} y δ = {delta}: DKW pide n = {n_dkw}; la ley exacta de D_n basta con n = {n_ex}")

With n=100n = 100 the DKW bound is between 1.071.07 and 1.271.27 times the exact tail throughout the table (and vacuous, above 11, for small tt). It is an excellent tail bound, where it is used. The final calculation quantifies the price of lacking the exact law: for ε=δ=0.05\varepsilon = \delta = 0.05, DKW requires 738738 observations and the exact law 731731, seven fewer.

One final calculation, for multiplicative processes, fixes the distinction between ensemble and time averages:

[ ]Ensemble versus time average: ×1.5 or ×0.6Browser
import numpy as np
from scipy.stats import binom

subida, bajada, n = 1.5, 0.6, 100
media_conjunto = (0.5 * subida + 0.5 * bajada) ** n
crec_log = 0.5 * np.log(subida) + 0.5 * np.log(bajada)
print(f"E[W_n] = 1.05^{n} = {media_conjunto:.1f}")
print(f"crecimiento temporal por paso (ley fuerte sobre ln): {crec_log:+.4f}  ->  W_n ~ {np.exp(crec_log * n):.4f}")

# W_n < 1 si y solo si el número de subidas k es menor que n·(-ln 0.6)/(ln 1.5 - ln 0.6)
k_crit = n * (-np.log(bajada)) / (np.log(subida) - np.log(bajada))
p_pierde = binom.cdf(np.ceil(k_crit) - 1, n, 0.5)
print(f"P(W_{n} < 1) = {p_pierde:.4f}")

rng = np.random.default_rng(0)
k = rng.binomial(n, 0.5, size=200_000)
W = subida**k * bajada ** (n - k)
print(f"media muestral de W_{n}: {W.mean():.1f}  (la media verdadera es {media_conjunto:.1f})   mediana: {np.median(W):.4f}")

Look at the last line: median W100W_{100} is 0.0050.005 (almost everything is lost), and the sample mean with 2⋅1052\cdot 10^5 replicates is around 6464, half the true expectation 131.5131.5, because it is sustained by trajectories so rare the sample barely sees them. This is the previous section’s lesson from the other side: with heavy tails, the sample average poorly measures expectation.

Common mistakes

Exercises

ProofWeak law for uncorrelated variables
Prove: Let X1,X2,…X_1, X_2, \dots be random variables with E[Xi]=μ\E[X_i] = \mu, Var⁡(Xi)≤σ2<∞\Var(X_i) \le \sigma^2 < \infty and Cov⁡(Xi,Xj)=0\Cov(X_i, X_j) = 0 for i≠ji \ne j. Then Xˉn→μ\bar X_n \to \mu in probability.
0
Use linearity of expectation, variance of a sum, and Chebyshev's inequality. Independence is not assumed.

Step 1 of 4. What is E[Xˉn]\E[\bar X_n] and what must be bounded?

ProofStrong law with a fourth moment
Prove: Let X1,X2,…X_1, X_2, \dots be iid with E[X14]<∞\E[X_1^4] < \infty and E[X1]=μ\E[X_1] = \mu. Then Xˉn→μ\bar X_n \to \mu almost surely.
0
Reduce to zero mean, bound the sum's fourth moment and finish with Borel-Cantelli. Consider why Chebyshev does not suffice.

Step 1 of 4. What is the first step?

NumericSamples required by DKW
Using the DKW inequality (Massart's constant), what is the smallest integer nn guaranteed to satisfy P(sup⁡x∣Fn(x)−F(x)∣≤0.02)≥0.95\Pr\big(\sup_x\abs{F_n(x) - F(x)} \le 0.02\big) \ge 0.95?
NumericTest examples required by Chebyshev
Test losses ℓi∈[0,1]\ell_i \in [0, 1] are iid. What is the smallest nn for which Chebyshev's inequality (using the best possible variance bound for variables in [0,1][0, 1]) guarantees P(∣R^n−R∣>0.01)≤0.05\Pr(\abs{\hat R_n - R} > 0.01) \le 0.05?
NumericFair value with a limited bankroll
In St Petersburg, the casino can pay at most 210=10242^{10} = 1024 euros, so the prize is min⁡(2K,210)\min(2^K, 2^{10}) with P(K=k)=2−k\Pr(K = k) = 2^{-k}. What is the expected prize?
QuizWhere does the strong law fail?
Let XiX_i be iid. For which laws does Xˉn\bar X_n not converge almost surely to a finite number?

More than one answer may be correct.

QuizAfter ten consecutive heads
A fair coin has produced 10 heads in a row, and 990990 more tosses will be made, giving n=1000n = 1000 total. Which claims are true?

More than one answer may be correct.

CodeECDF and DKW band
Implement two functions. ecdf(x) receives sample x and returns function F such that F(t) is the empirical distribution function at t (a scalar or NumPy array), i.e. the fraction of data less than or equal to t. dkw_band(x, delta) returns function band such that band(t) is the pair (inferior, superior) of DKW band bounds at level 1−δ1 - \delta, i.e. Fn(t)∓εnF_n(t) \mp \varepsilon_n with εn=ln⁡(2/δ)/(2n)\varepsilon_n = \sqrt{\ln(2/\delta)/(2n)}, clipped to [0,1][0, 1]. Tests check values and simulated coverage.
import numpy as np

def ecdf(x):
  # devuelve una función F(t) = fracción de datos <= t, vectorizada en t
  pass

def dkw_band(x, delta):
  # devuelve una función band(t) -> (inferior, superior), recortada a [0, 1]
  pass
Shift+Enter to run

Summary

Key idea
The law of large numbers says the average of iid variables with finite expectation converges to that expectation: in probability (weak law, from finite variance and Chebyshev, or finite mean alone by truncation) and almost surely (strong law, from a fourth moment and Borel-Cantelli, or finite mean alone by Etemadi). Finite expectation is exactly the condition: without it the average diverges or never stabilizes (Pareto with α≤1\alpha \le 1, Cauchy, St Petersburg), and Kolmogorov’s zero-one law ensures any limit is constant. The law gives no rate: with variance, n−1/2n^{-1/2}; with tails α∈(1,2)\alpha \in (1, 2), n1/α−1n^{1/\alpha - 1}, arbitrarily slowly. It applies to the entire distribution function simultaneously: Glivenko-Cantelli gives uniform convergence of FnF_n without assumptions, and DKW quantifies it, P(Dn>ε)≤2e−2nε2\Pr(D_n > \varepsilon) \le 2e^{-2n\varepsilon^2}, with a simultaneous distribution-free confidence band.