TExcelTAD
Home › Probability Theory › Markov's and Chebyshev's Inequalities

Markov's and Chebyshev's Inequalities

Often you know only a mean, or a mean and a variance, and need to bound the chance of an extreme outcome. Two simple inequalities do this for every distribution. They are rarely tight, but they always hold, and they are the key step in proving the law of large numbers.

Markov's inequality

For a non-negative random variable XX and any a>0a > 0:

Pr⁡[X≥a]≤E[X]a\Pr[X \ge a] \le \frac{E[X]}{a}

Proof: E[X]≥E[X⋅IX≥a]≥aPr⁡[X≥a]E[X] \ge E[X \cdot I_{X \ge a}] \ge a \Pr[X \ge a]. If the average response time is 100 ms, at most 10% of requests take 1 second or more, whatever the distribution.

Chebyshev's inequality

Apply Markov to (X−μ)2(X - \mu)^2 with a=k2σ2a = k^2\sigma^2:

Pr⁡[∣X−μ∣≥kσ]≤1k2\Pr\big[\lvert X - \mu \rvert \ge k\sigma\big] \le \frac{1}{k^2}

At most 1/41/4 of any distribution lies 2 or more standard deviations from the mean, at most 1/91/9 beyond 3. Compare the normal distribution's 4.6% and 0.27%: Chebyshev is the worst case, the price for assuming nothing about the shape.

python · try it yourself
import numpy as np

rng = np.random.default_rng(1)
samples = {
    "normal": rng.normal(0, 1, 500_000),
    "exponential": rng.exponential(1, 500_000),
    "uniform": rng.uniform(0, 1, 500_000),
    "two-point +-1": rng.choice([-1.0, 1.0], 500_000),
}
for k in [1.5, 2, 3]:
    row = []
    for name, x in samples.items():
        mu, sd = x.mean(), x.std()
        row.append(f"{name} {np.mean(np.abs(x - mu) >= k * sd):.4f}")
    print(f"k={k}: Chebyshev bound {1 / k ** 2:.4f} | " + " | ".join(row))
k=1.5: Chebyshev bound 0.4444 | normal 0.1332 | exponential 0.0820 | uniform 0.1339 | two-point +-1 0.0000
k=2: Chebyshev bound 0.2500 | normal 0.0459 | exponential 0.0501 | uniform 0.0000 | two-point +-1 0.0000
k=3: Chebyshev bound 0.1111 | normal 0.0029 | exponential 0.0185 | uniform 0.0000 | two-point +-1 0.0000

All observed frequencies stay below the bound. The bound can be attained: the distribution with Pr⁡[X=±k]=12k2\Pr[X = \pm k] = \frac{1}{2k^2} and Pr⁡[X=0]=1−1k2\Pr[X = 0] = 1 - \frac{1}{k^2} has standard deviation 1 and exactly 1/k21/k^2 of its mass at distance kk.

When the bounds are useful

These inequalities shine when the distribution is unknown or complicated: the number of comparisons of a randomized algorithm, the load on a server, the error of a simulation. For example, if a randomized algorithm's running time has mean TT, Markov's inequality says it exceeds 2T2T with probability at most 1/21/2; by stopping and restarting after 2T2T steps, kk restarts all fail with probability at most 2−k2^{-k}.

For sums of many independent pieces, much sharper Chernoff bounds exist, decreasing exponentially in the number of standard deviations (Deviation from the Mean).

python · try it yourself
import math

# Sum of n fair coin flips: P(S >= 0.6 n)
for n in [50, 100, 500]:
    mu, var = n / 2, n / 4
    a = 0.6 * n
    markov = mu / a
    cheb = var / (a - mu) ** 2                # one-sided use of Chebyshev (an over-estimate)
    exact = sum(math.comb(n, k) for k in range(math.ceil(a), n + 1)) / 2 ** n
    print(f"n={n:3d}  Markov {markov:.3f}  Chebyshev {cheb:.4f}  exact {exact:.2e}")
n= 50  Markov 0.833  Chebyshev 0.5000  exact 1.01e-01
n=100  Markov 0.833  Chebyshev 0.2500  exact 2.84e-02
n=500  Markov 0.833  Chebyshev 0.0500  exact 4.47e-06

Markov does not improve with nn; Chebyshev improves like 1/n1/n; the truth improves exponentially.

In software

Markov-style reasoning bounds tail latency from averages, memory use from expected sizes, and the probability that a hash table bucket overflows. Chebyshev gives sample sizes for simulations and A/B tests that are valid without assuming normality. Many proofs in randomized algorithms are "compute the expectation, then apply Markov".

Exercises

Exercise 1: Markov for queue length

A queue has average length 3. Bound the probability that it holds at least 15 items.

Answer

At most 1/51/5.

Solution

Pr⁡[X≥15]≤3/15\Pr[X \ge 15] \le 3/15.

Exercise 2: Chebyshev for exam scores

Scores have mean 70 and standard deviation 8. What fraction of students at least must score between 54 and 86?

Answer

At least 75%.

Solution

54 and 86 are k=2k = 2 standard deviations from the mean; at most 1/41/4 lie outside.

Exercise 3: Sample size by Chebyshev (code)

How many fair coin tosses guarantee, by Chebyshev, that the proportion of heads is within 0.05 of 1/21/2 with probability at least 0.95? Check how often it fails in simulation.

Answer

n=2000n = 2000; the actual failure rate is far below 5%.

Solution

Var⁡(p^)=14n\operatorname{Var}(\hat{p}) = \frac{1}{4n}, so Pr⁡[∣p^−0.5∣≥0.05]≤14n⋅0.0025=100n≤0.05\Pr[\lvert \hat{p} - 0.5 \rvert \ge 0.05] \le \frac{1}{4n \cdot 0.0025} = \frac{100}{n} \le 0.05 needs n≥2000n \ge 2000.

python · try it yourself
import numpy as np

rng = np.random.default_rng(7)
n = 2000
props = rng.binomial(n, 0.5, 100_000) / n
print("failure rate:", (np.abs(props - 0.5) >= 0.05).mean())
failure rate: 1e-05

The normal approximation shows that about 400 tosses would already suffice (Using the CLT).

Test yourself

Markov's inequality applies to…

  1. any random variable
  2. non-negative random variables
  3. only normal variables
  4. only discrete variables

By Chebyshev, at most what fraction of a distribution lies 3 or more standard deviations from its mean?

  1. 0.27%
  2. 1/3
  3. 1/9
  4. 1/27