Skip to content
LeetQuant
F5 Statistics and Inference

F5 · Statistics and Inference · Lesson 3 of 4

Likelihood and Maximum Likelihood

Write down a likelihood, maximise it for the standard models, get a standard error from the Fisher information, and know where the MLE is biased.

18 min

The likelihood function

A model gives a density (or mass function) f(x;θ)f(x; \theta). Once the data x1,…,xnx_1, \dots, x_n are observed, read the same formula as a function of the parameter:

L(θ)=∏i=1nf(xi;θ),ℓ(θ)=log⁡L(θ)=∑i=1nlog⁡f(xi;θ).L(\theta) = \prod_{i=1}^n f(x_i; \theta), \qquad \ell(\theta) = \log L(\theta) = \sum_{i=1}^n \log f(x_i; \theta) .

L(θ)L(\theta) says how probable the observed data would be if the parameter were θ\theta. It is not a probability distribution over θ\theta: it need not integrate to one, and only ratios L(θ1)/L(θ2)L(\theta_1)/L(\theta_2) are meaningful. Multiplying by a prior and normalising would make it a Bayesian posterior; without a prior it is just a ranking of parameter values.

The maximum-likelihood estimate θ^\hat\theta is the value that makes the data most probable. Work with ℓ\ell: the product becomes a sum, and the maximiser is the same because log⁡\log is increasing. The recipe:

  1. Write ℓ(θ)\ell(\theta), dropping terms that do not involve θ\theta.
  2. Solve the score equation ℓ′(θ)=0\ell'(\theta) = 0.
  3. Check it is a maximum (ℓ′′<0\ell'' < 0) and check the boundary of the parameter space.

The four standard models

Bernoulli(pp), kk successes in nn trials: ℓ(p)=klog⁡p+(n−k)log⁡(1−p)\ell(p) = k \log p + (n-k)\log(1-p). Setting ℓ′(p)=k/p−(n−k)/(1−p)=0\ell'(p) = k/p - (n-k)/(1-p) = 0 gives p^=k/n\hat p = k/n.

Poisson(λ\lambda): ℓ(λ)=(∑xi)log⁡λ−nλ\ell(\lambda) = \left(\sum x_i\right)\log\lambda - n\lambda (dropping −∑log⁡xi!-\sum \log x_i!). Then ℓ′(λ)=∑xi/λ−n=0\ell'(\lambda) = \sum x_i / \lambda - n = 0 gives λ^=xˉ\hat\lambda = \bar x.

Exponential(λ\lambda), density λe−λx\lambda e^{-\lambda x}: ℓ(λ)=nlog⁡λ−λ∑xi\ell(\lambda) = n \log\lambda - \lambda \sum x_i, so n/λ=∑xin/\lambda = \sum x_i and λ^=1/xˉ\hat\lambda = 1/\bar x.

Normal(μ,σ2\mu, \sigma^2): ℓ=−n2log⁡σ2−12σ2∑(xi−μ)2\ell = -\tfrac n2 \log \sigma^2 - \tfrac{1}{2\sigma^2}\sum (x_i - \mu)^2. The μ\mu-derivative gives μ^=xˉ\hat\mu = \bar x. Substituting and differentiating in σ2\sigma^2:

−n2σ2+12σ4∑(xi−xˉ)2=0⟹σ^2=1n∑(xi−xˉ)2.-\frac{n}{2\sigma^2} + \frac{1}{2\sigma^4}\sum (x_i - \bar x)^2 = 0 \quad\Longrightarrow\quad \hat\sigma^2 = \frac1n \sum (x_i - \bar x)^2 .

A model where calculus fails: Uniform(0,θ0, \theta). L(θ)=θ−nL(\theta) = \theta^{-n} for θ≥max⁡xi\theta \ge \max x_i and 00 otherwise. It is decreasing in θ\theta, so the maximum sits on the boundary: θ^=max⁡xi\hat\theta = \max x_i. Setting a derivative to zero would find nothing.

Invariance

If θ^\hat\theta is the MLE of θ\theta, then g(θ^)g(\hat\theta) is the MLE of g(θ)g(\theta). The MLE of σ\sigma is σ^2\sqrt{\hat\sigma^2}; the MLE of the exponential mean is xˉ\bar x; the MLE of P(X=0)=e−λP(X = 0) = e^{-\lambda} for a Poisson is e−xˉe^{-\bar x}. No new optimisation is needed. (Unbiasedness is not invariant: if θ^\hat\theta is unbiased, g(θ^)g(\hat\theta) usually is not.)

Standard errors from the curvature

A sharply peaked log-likelihood pins θ\theta down; a flat one does not. The Fisher information per observation measures the expected curvature:

I(θ)=−E ⁣[∂2∂θ2log⁡f(X;θ)].I(\theta) = -\mathbb{E}\!\left[\frac{\partial^2}{\partial\theta^2} \log f(X; \theta)\right] .

Under regularity conditions (the support does not depend on θ\theta, the true value is interior, the model is correct), the MLE is consistent and asymptotically normal:

θ^  ≈  N ⁣(θ,  1n I(θ)),SE⁡(θ^)≈1n I(θ^).\hat\theta \;\approx\; N\!\left(\theta, \; \frac{1}{n\,I(\theta)}\right), \qquad \operatorname{SE}(\hat\theta) \approx \frac{1}{\sqrt{n\,I(\hat\theta)}} .

The Cramér–Rao bound says no unbiased estimator has variance below 1/(nI(θ))1/(n I(\theta)), so the MLE is asymptotically as efficient as possible. In practice you can also use the observed information −ℓ′′(θ^)-\ell''(\hat\theta) in place of nI(θ^)n I(\hat\theta).

ModelI(θ)I(\theta) per observationSE⁡\operatorname{SE} of MLE
Bernoulli(pp)1/(p(1−p))1/(p(1-p))p^(1−p^)/n\sqrt{\hat p(1-\hat p)/n}
Poisson(λ\lambda)1/λ1/\lambdaλ^/n\sqrt{\hat\lambda/n}
Exponential(λ\lambda)1/λ21/\lambda^2λ^/n\hat\lambda/\sqrt n
Normal mean, σ\sigma known1/σ21/\sigma^2σ/n\sigma/\sqrt n

Likelihood also gives a test. The likelihood-ratio statistic 2[ℓ(θ^)−ℓ(θ0)]2[\ell(\hat\theta) - \ell(\theta_0)] is approximately χ12\chi^2_1 under H0:θ=θ0H_0: \theta = \theta_0, so values above 1.962≈3.841.96^2 \approx 3.84 reject at 5%.

Worked example

is the coin fair? Three ways

A coin lands heads 60 times in 100 flips. Find the MLE of pp, its standard error, a 95% Wald interval, and the likelihood-ratio test of p=0.5p = 0.5.

Show solution

p^=60/100=0.6\hat p = 60/100 = 0.6.

With I(p)=1/(p(1−p))I(p) = 1/(p(1-p)), SE⁡=0.6×0.4/100=0.0024≈0.049\operatorname{SE} = \sqrt{0.6 \times 0.4 / 100} = \sqrt{0.0024} \approx 0.049. The Wald interval is 0.6±1.96×0.049=0.6±0.0960.6 \pm 1.96 \times 0.049 = 0.6 \pm 0.096, or [0.504,0.696][0.504, 0.696], which just excludes 0.50.5.

The likelihood ratio:

2[60log⁡0.60.5+40log⁡0.40.5]=2 [10.939−8.926]≈4.03.2\left[60 \log\frac{0.6}{0.5} + 40 \log\frac{0.4}{0.5}\right] = 2\,[10.939 - 8.926] \approx 4.03 .

That exceeds 3.843.84; the p-value is P(χ12>4.03)≈0.045P(\chi^2_1 > 4.03) \approx 0.045. The z-test using the null standard error 0.25/100=0.05\sqrt{0.25/100} = 0.05 gives z=0.1/0.05=2z = 0.1/0.05 = 2 and p-value 0.04550.0455. All three agree here because nn is large and p^\hat p is not near 0 or 1. With small samples or extreme p^\hat p the Wald interval behaves worst (it can even extend below 0); the likelihood-ratio approach holds up best.

Worked example

arrival rate of trades, and its bias

You record 40 gaps between trades, modelled as i.i.d. exponential, and they sum to 20 seconds. Estimate the arrival rate λ\lambda with a standard error and a 95% interval. Is the estimator biased?

Show solution

λ^=n/∑xi=40/20=2\hat\lambda = n / \sum x_i = 40/20 = 2 trades per second.

With I(λ)=1/λ2I(\lambda) = 1/\lambda^2, SE⁡≈λ^/n=2/40≈0.316\operatorname{SE} \approx \hat\lambda / \sqrt n = 2/\sqrt{40} \approx 0.316, so the interval is 2±1.96×0.316=2±0.622 \pm 1.96 \times 0.316 = 2 \pm 0.62, or about [1.38,2.62][1.38, 2.62].

Bias: ∑Xi∼Gamma(n,λ)\sum X_i \sim \text{Gamma}(n, \lambda) and E[1/∑Xi]=λ/(n−1)\mathbb{E}[1/\sum X_i] = \lambda/(n-1), so

E[λ^]=nn−1 λ.\mathbb{E}[\hat\lambda] = \frac{n}{n-1}\,\lambda .

The MLE overestimates the rate by a factor n/(n−1)n/(n-1): 2.6% here, 25% with n=5n = 5 (a simulation with λ=2\lambda = 2, n=5n = 5 averages 2.502.50). The unbiased version is (n−1)/∑xi=39/20=1.95(n-1)/\sum x_i = 39/20 = 1.95. Note that the MLE of the mean gap, xˉ\bar x, is unbiased; the bias appears because 1/x1/x is convex (Jensen's inequality).

MLE bias: the normal variance

The MLE σ^2=1n∑(xi−xˉ)2\hat\sigma^2 = \tfrac1n\sum (x_i - \bar x)^2 is biased. Deviations are measured from xˉ\bar x, which is fitted to the same data and therefore closer to the points than μ\mu is. Since ∑(xi−xˉ)2/σ2∼χn−12\sum (x_i - \bar x)^2 / \sigma^2 \sim \chi^2_{n-1},

E[σ^2]=n−1n σ2.\mathbb{E}[\hat\sigma^2] = \frac{n-1}{n}\,\sigma^2 .

Dividing by n−1n - 1 instead gives the unbiased s2s^2. The bias is O(1/n)O(1/n) and vanishes asymptotically, which is the general pattern for MLEs. In regression with pp fitted coefficients the same logic gives a divisor of n−pn - p. A quick simulation confirms the factor for n=10n = 10:

import random

random.seed(3)
n, reps, total = 10, 100_000, 0.0
for _ in range(reps):
    x = [random.gauss(0, 1) for _ in range(n)]
    m = sum(x) / n
    total += sum((v - m) ** 2 for v in x) / n  # MLE divides by n
print(round(total / reps, 3))  # 0.899, close to (n - 1) / n = 0.9

Knowledge check

Daily counts of a rare event are 2,0,3,1,42, 0, 3, 1, 4, modelled as Poisson. What is the MLE of the probability that a day has no events?

Knowledge check

Ten draws from Uniform(0,θ0, \theta) have mean 4.6 and maximum 8.4. What is the maximum-likelihood estimate of θ\theta?

Knowledge check

An estimate of a win probability is 0.55 from 400 independent trades. What is the approximate standard error from the Fisher information?

Practice problems

Finished reading?

Answer the 3 knowledge checks to complete this lesson (0 done).