The law of large numbers, Markov's inequality and Chebyshev's inequality
Ten problems on the law of large numbers and the inequalities behind it: Markov's bound on a latency, Chebyshev's bound against the normal's exact tail, Chebyshev proved from Markov with the distribution that makes it tight, the bound against a uniform's exact tail, the weak law for die rolls, the sample size for estimating a coin's bias, a Monte Carlo estimate of π, the batch size for a minibatch gradient, the variance of an average of correlated samples and why proportions settle while counts spread, with worked solutions and the mistakes of using Markov on a variable that can be negative, putting σ where σ² belongs, dividing by n instead of √n, averaging correlated samples as if they were independent and expecting a coin to even out.
Before you start
The law of large numbers is the reason an average of many noisy measurements can be trusted: as the sample grows, the sample mean settles on the true mean. Every Monte Carlo estimate, every minibatch gradient and every test-set accuracy relies on it. Its simplest proof is two lines long and rests on two inequalities that hold for any distribution with a mean and, for the second, a variance: Markov's, which bounds a tail using only the mean, and Chebyshev's, which bounds the distance from the mean using the variance. These ten problems use both bounds, compare them with exact answers to see how much they give away, prove the weak law and use it to size a sample, a Monte Carlo run and a minibatch, and then look at what changes when samples are correlated and why a fair coin's proportion of heads settles while its count of extra heads does not. The five mistakes at the end are the ones that give a believable number: Markov applied to a variable that can be negative, σ written where σ2 belongs, an error divided by n instead of ,n, correlated samples averaged as if independent, and a coin expected to make up for its past.
Markov's inequality. If X≥0 and ,a>0, then .P(X≥a)≤aE[X].
Chebyshev's inequality. If X has mean μ and variance ,σ2, then for every ,t>0,.P(∣X−μ∣≥t)≤t2σ2. With t=kσ this reads .P(∣X−μ∣≥kσ)≤k21.
The sample mean. For independent, identically distributed (i.i.d.) X1,…,Xn with mean μ and variance ,σ2,Xˉn=n1∑iXi has E[Xˉn]=μ and ,Var(Xˉn)=σ2/n, so its standard deviation is .σ/n.
The weak law of large numbers. For every ,ε>0,,P(∣Xˉn−μ∣≥ε)≤nε2σ2, which tends to 0 as .n→∞.
Proportions. The fraction p^ of n independent trials in which an event of probability p happens is the sample mean of indicators, each with mean p and variance .p(1−p)≤41.
Correlation. For a sum, .Var(∑iXi)=∑iVar(Xi)+∑i=jCov(Xi,Xj).Φ is the standard normal CDF, as on the normal-distribution page.
A service's response time T is never negative and has mean 200 ms. What does Markov's inequality say about P(T≥1000) and about ?P(T≥100)? If T is in fact exponential with mean 200 ms, what is ?P(T≥1000)?
·
A measurement has mean 50 and variance .25. Bound P(∣X−50∣≥15) with Chebyshev's inequality, and give the guarantee it implies for .P(35<X<65). Compare with the exact value if X is normal.
··
Prove Chebyshev's inequality from Markov's. Then let k>1 and let X equal μ−kσ and μ+kσ with probability 2k21 each, and μ otherwise. Show that X has mean μ and variance ,σ2, and that Chebyshev's bound is an equality for it.
··
Let X be uniform on .(0,1). Compute P(∣X−21∣≥0.4) and P(∣X−21∣≥0.3) exactly, and compare each with Chebyshev's bound.
··
A fair die is rolled n times. Use the weak law to bound the probability that the average roll is 0.1 or more away from 3.5 when ,n=1000, and find the n that makes the bound .0.01. What does the normal approximation give for ?n=1000?
··
A coin of unknown bias p is flipped n times and p^ is the fraction of heads. Using only ,p(1−p)≤41, how large must n be for Chebyshev to guarantee ?P(∣p^−p∣≥0.05)≤0.05? What n does the normal approximation suggest?
··
To estimate ,π, draw n=10000 points uniformly in the unit square and let p^ be the fraction with ;x2+y2≤1; the estimate is .4p^. Find its standard deviation, and bound .P(∣4p^−π∣≥0.05).
··
Each example's gradient component has mean g and variance ,4, independently across examples. Find the standard deviation of the minibatch average over B examples, the B that makes it ,0.1, and Chebyshev's bound on P(∣gˉ−g∣≥0.25) at that .B.
···
Let X1,…,Xn each have variance ,σ2, with Cov(Xi,Xj)=ρσ2 for every .i=j. Find Var(Xˉn) and its limit as .n→∞. Evaluate for ,σ2=1,ρ=0.1 and ,n=100, and find the number of independent samples that would give the same variance.
···
A fair coin is flipped n times, with H heads. Find the standard deviation of the proportion H/n and of the excess H−n/2 for n=100 and .n=10000. Then find P(H=n/2) for both, given that it is about 2/(πn) for large .n.
Answers
Markov: ,P(T≥1000)≤0.2, and nothing useful about ;P(T≥100); for an exponential the true value is e−5≈0.0067
,P(∣X−50∣≥15)≤91≈0.111, so ;P(35<X<65)≥98≈0.889; for a normal the tail is only 0.0027
Chebyshev is Markov applied to ,(X−μ)2, and the three-point distribution attains 1/k2 exactly, so no better bound holds for every distribution
Exact 0.2 against a bound of ,0.521, and exact 0.4 against 0.926
The bound is 0.292 at ,n=1000, and n≥29167 makes it ;0.01; the normal approximation gives about 0.064
Chebyshev needs ;n≥2000; the normal approximation suggests 385
Standard deviation ;≈0.0164;,P(∣4p^−π∣≥0.05)≤0.108, so the estimate is within 0.05 of π at least 89% of the time
;2/B;;B=400; the bound is 0.16
;Var(Xˉn)=nσ2+nn−1ρσ2→ρσ2; here ,0.109, the same as about 9 independent samples
Proportion: 0.05 then ;0.005; excess heads: 5 then ;50; exactly half heads: 0.080 then 0.008
Worked solutions
Problem 1
A service's response time T is never negative and has mean 200 ms. What does Markov's inequality say about P(T≥1000) and about ?P(T≥100)? If T is in fact exponential with mean 200 ms, what is ?P(T≥1000)?
P(T≥1000)≤1000200=0.2Markov with ;a=1000;,T≥0, so it applies.
P(T≥100)≤100200=2Markov with .a=100.
A bound of 2 says nothingEvery probability is at most 1 already. Markov is only useful for a above the mean.
Exponential: ,P(T≥t)=e−t/200, so P(T≥1000)=e−5The exponential's tail.
Markov: ,P(T≥1000)≤0.2, and nothing useful about ;P(T≥100); for an exponential the true value is e−5≈0.0067The bound is thirty times the truth here because it uses only the mean. It holds for every nonnegative distribution with that mean, including the worst one: T=1000 with probability 0.2 and T=0 otherwise, where it is exact.
Problem 2
A measurement has mean 50 and variance .25. Bound P(∣X−50∣≥15) with Chebyshev's inequality, and give the guarantee it implies for .P(35<X<65). Compare with the exact value if X is normal.
P(∣X−50∣≥15)≤15225=91Chebyshev with σ2=25 and .t=15.
,15=3σ, so this is 1/k2 with k=3.σ=5.
P(35<X<65)=1−P(∣X−50∣≥15)≥98The complement.
For a normal: P(∣X−50∣≥15)=2(1−Φ(3))=0.0027Three standard deviations, both tails.
,P(∣X−50∣≥15)≤91≈0.111, so ;P(35<X<65)≥98≈0.889; for a normal the tail is only 0.0027Chebyshev knows nothing about the shape, so it must allow for heavy tails. It is the guarantee to quote when the distribution is unknown, and the normal's 99.7% is the one to quote when it is known.
Problem 3
Prove Chebyshev's inequality from Markov's. Then let k>1 and let X equal μ−kσ and μ+kσ with probability 2k21 each, and μ otherwise. Show that X has mean μ and variance ,σ2, and that Chebyshev's bound is an equality for it.
Let ,Y=(X−μ)2, so Y≥0 and E[Y]=σ2The definition of the variance.
∣X−μ∣≥t exactly when Y≥t2Both sides are nonnegative, so squaring keeps the inequality.
P(∣X−μ∣≥t)=P(Y≥t2)≤t2E[Y]=t2σ2Markov on Y with .a=t2.
For the three-point :X:E[X]=μThe two outer values are symmetric about μ and equally likely.
Var(X)=2⋅2k21(kσ)2=σ2Only the outer values are away from ,μ, each by .kσ.
P(∣X−μ∣≥kσ)=2⋅2k21=k21Exactly the bound.
Chebyshev is Markov applied to ,(X−μ)2, and the three-point distribution attains 1/k2 exactly, so no better bound holds for every distributionFor k=2 it puts 81 at each of μ±2σ and 43 at .μ. A smaller bound, like the one in Mistake 2, fails on a distribution of this kind.
Problem 4
Let X be uniform on .(0,1). Compute P(∣X−21∣≥0.4) and P(∣X−21∣≥0.3) exactly, and compare each with Chebyshev's bound.
μ=21 and σ2=121The uniform's mean and variance on an interval of length .1.
∣X−21∣≥0.4 means X≤0.1 or :X≥0.9: probability 0.2Two end pieces of length .0.1.
Chebyshev: 0.161/12≈0.521,t=0.4,.t2=0.16.
∣X−21∣≥0.3 means X≤0.2 or :X≥0.8: probability 0.4Two end pieces of length .0.2.
Chebyshev: 0.091/12≈0.926.t=0.3.
Exact 0.2 against a bound of ,0.521, and exact 0.4 against 0.926The bounds hold, with room to spare: a uniform has no tails at all. In units of σ≈0.289 these are k≈1.39 and ,k≈1.04, where 1/k2 is barely below .1.
Problem 5
A fair die is rolled n times. Use the weak law to bound the probability that the average roll is 0.1 or more away from 3.5 when ,n=1000, and find the n that makes the bound .0.01. What does the normal approximation give for ?n=1000?
μ=3.5 and σ2=61∑k=16k2−3.52=691−12.25=1235.E[X2]−(E[X])2.
P(∣Xˉ−3.5∣≥0.1)≤1000⋅0.0135/12≈0.292The weak law with .ε=0.1.
n⋅0.0135/12≤0.01 needs n≥29166.7Solve for .n.
Normal: Xˉ has standard deviation (35/12)/1000≈0.0540.σ/n.
2(1−Φ(0.1/0.0540))=2(1−Φ(1.85))Both tails, at .z≈1.85.
The bound is 0.292 at ,n=1000, and n≥29167 makes it ;0.01; the normal approximation gives about 0.064Chebyshev's guarantee is about four and a half times the likely value. The law of large numbers says the average converges; the central limit theorem says how fast in a form sharp enough to plan with.
Problem 6
A coin of unknown bias p is flipped n times and p^ is the fraction of heads. Using only ,p(1−p)≤41, how large must n be for Chebyshev to guarantee ?P(∣p^−p∣≥0.05)≤0.05? What n does the normal approximation suggest?
Var(p^)=np(1−p)≤4n1The sample mean of indicators.
P(∣p^−p∣≥0.05)≤4n⋅0.00251=n100Chebyshev with .t=0.05.
n100≤0.05 needs n≥2000Solve for .n.
Normal: 1.964n1≤0.05 needs n≥(0.051.96)2⋅41=384.16A two-sided 95% margin of .0.05.
Chebyshev needs ;n≥2000; the normal approximation suggests 385The worst case p=21 is built into both. A poll of about 400 for a ±5 point margin is the normal figure; 2000 is what can be promised with no assumption about the shape of the sampling distribution.
Problem 7
To estimate ,π, draw n=10000 points uniformly in the unit square and let p^ be the fraction with ;x2+y2≤1; the estimate is .4p^. Find its standard deviation, and bound .P(∣4p^−π∣≥0.05).
Each point lands in the quarter disk with probability p=4π≈0.7854The quarter disk has area π/4 and the square area .1.
E[4p^]=π and Var(4p^)=n16p(1−p)Scaling by 4 multiplies the variance by .16.
16⋅0.7854⋅0.2146/10000≈2.70×10−4.p(1−p)≈0.1685.
Standard deviation ≈0.0164The square root.
P(∣4p^−π∣≥0.05)≤0.00252.70×10−4≈0.108Chebyshev with .t=0.05.
Standard deviation ;≈0.0164;,P(∣4p^−π∣≥0.05)≤0.108, so the estimate is within 0.05 of π at least 89% of the timeThe error shrinks like :1/n: one more correct digit costs a hundred times as many points. That rate, and not the dimension of the problem, is why Monte Carlo is used for high-dimensional integrals.
Problem 8
Each example's gradient component has mean g and variance ,4, independently across examples. Find the standard deviation of the minibatch average over B examples, the B that makes it ,0.1, and Chebyshev's bound on P(∣gˉ−g∣≥0.25) at that .B.
,Var(gˉ)=4/B, so its standard deviation is 2/BThe sample mean of B i.i.d. values.
2/B=0.1 gives B=20Solve.
B=400Square.
P(∣gˉ−g∣≥0.25)≤0.2524/400=0.06250.01Chebyshev with .σ2=0.01.
;2/B;;B=400; the bound is 0.16Halving the noise of a gradient estimate takes four times the batch, which is why very large batches give diminishing returns per example. Examples drawn without replacement from a finite dataset, or correlated as in Problem 9, change the .4/B.
Problem 9
Let X1,…,Xn each have variance ,σ2, with Cov(Xi,Xj)=ρσ2 for every .i=j. Find Var(Xˉn) and its limit as .n→∞. Evaluate for ,σ2=1,ρ=0.1 and ,n=100, and find the number of independent samples that would give the same variance.
Var(∑iXi)=nσ2+n(n−1)ρσ2n variances and n(n−1) ordered pairs .i=j.
Var(Xˉn)=nσ2+nn−1ρσ2Divide by .n2.
As n→∞ this tends to ,ρσ2, not 0The first term vanishes and the second tends to .ρσ2.
For ,σ2=1,,ρ=0.1,:n=100:0.01+0.99⋅0.1=0.109Step 2.
;Var(Xˉn)=nσ2+nn−1ρσ2→ρσ2; here ,0.109, the same as about 9 independent samplesWith a shared positive correlation the average never settles: the part of the noise that all samples share does not average out. Neighboring frames of a video, or a minibatch drawn from one document, behave like this.
Problem 10
A fair coin is flipped n times, with H heads. Find the standard deviation of the proportion H/n and of the excess H−n/2 for n=100 and .n=10000. Then find P(H=n/2) for both, given that it is about 2/(πn) for large .n.
,Var(H)=n⋅21⋅21=4n, so H has standard deviation 21nA binomial count.
H−n/2 has the same standard deviation, :21n:5 and 50Subtracting a constant changes nothing but the mean.
H/n has standard deviation :2nn=2n1:0.05 and 0.005Dividing by n divides the standard deviation by .n.
P(H=5000∣n=10000)≈2/(10000π)≈0.0080The approximation; the exact value is .0.00798.
Proportion: 0.05 then ;0.005; excess heads: 5 then ;50; exactly half heads: 0.080 then 0.008The law of large numbers is about the proportion. The excess of heads over half grows like ,n, and an exact tie becomes ten times less likely. The proportion settles because the excess grows more slowly than ,n, not because the coin corrects itself (Mistake 5).
Where this goes wrong
1. Using Markov on a variable that can be negative
Markov's inequality needs only the mean, and a change in temperature has a mean.
A daily change X has E[X]=1Right so far.
“By Markov, .P(X≥4)≤41.”The condition that is missing: Markov needs .X≥0. Large negative values can pull the mean down while the upper tail stays heavy.
P(X≥4)≤0.25Let X=−10 or 12 with probability 21 each. Its mean is ,1, and ,P(X≥4)=0.5, twice the claimed bound.
2. Putting σ where σ² belongs
Problem 2's numbers are given as a mean and a variance, and a standard deviation of 5 is the number that comes to mind.
,μ=50,,σ=5,t=15Right so far.
“Chebyshev: .P(∣X−50∣≥15)≤σ/t2.”The slip that causes the mistake: the numerator is the variance ,σ2=25, which is what makes the two sides of the inequality the same units.
P(∣X−50∣≥15)≤2255≈0.0222The distribution of Problem 3 with ,k=3, putting 181 at each of 35 and 65 and the rest at ,50, has variance 25 and ,P(∣X−50∣≥15)=91≈0.111, five times the claimed bound.
3. Dividing by n instead of √n
The average divides the sum by ,n, and the same n seems to divide the noise.
Var(gˉ)=4/BRight so far: Problem 8.
“So the standard deviation of gˉ is .2/B.”The slip that causes the mistake: the variance is divided by ,B, so the standard deviation is divided by .B.
a batch of B=20 gives standard deviation 0.1At B=20 it is ,2/20≈0.447, more than four times the target. The batch that gives 0.1 is .400.
4. Averaging correlated samples as if they were independent
The formula σ2/n is the one remembered, and the samples in Problem 9 each have variance .σ2.
n=100 samples, each with variance 1Right so far.
“,Var(Xˉ)=σ2/n=0.01, so the average has standard deviation .0.1.”The condition that is missing: σ2/n needs the covariances to be .0. Here every pair has covariance .0.1.
standard deviation of Xˉ=0.1It is ,0.109≈0.330, more than three times larger. Error bars computed this way look tight on data that is far less informative than its size suggests.
5. Expecting the coin to even out
The law of large numbers says the proportion of heads tends to ,21, and after a run of heads it seems that tails must now be due.
After 100 flips there have been 60 headsRight so far.
“To bring the proportion back to ,21, the coming flips must favor tails.”The habit that causes the mistake: reading a statement about the long-run proportion as a force acting on the next flips. Each flip is still fair.
the next 100 flips are expected to give fewer than 50 headsThey are expected to give exactly .50. After 10000 more flips the expected total is 5060 heads out of ,10100, a proportion of :0.501: the excess of 10 is still there in expectation, but it is swamped by the new flips, not canceled.