Skip to content

Maximum likelihood

Pick the parameter that makes the data you saw most probable, by sliding the model until its curve fits the points best.

Helps to know first
This topic

First, the picture

Three data points sit on a line. A bell slides along them, and the heights it gives the points are multiplied. Watch where the product peaks.

Which value fits best

A bell with spread 2 slides along the data 3, 5 and 7; its heights there multiply into the likelihood.

The data 3, 5 and 7, and a bell with spread 2. Each stem is the bell's height at a data point; their product is the likelihood.

centre μ
1.0
likelihood L(μ)
0.00000724
log-likelihood ℓ(μ)
−11.836

Predict first. Where will the product of the three heights be largest?

0.00 / 13.00 s
Describe this picture

Three panels on one horizontal scale from 0 to 10. On top, the data 3, 5 and 7 as dots on an axis, and a bell curve with standard deviation 2 whose centre μ\mu can move; a stem from each dot up to the curve shows the curve’s height there. Below it, “likelihood L(μ)”, the product of the three heights drawn against μ\mu, and under that, “log-likelihood ℓ(μ)”, its logarithm. Before the clip a question asks where the likelihood will peak: at the smallest, the middle or the largest data value. A tap picks one and starts the clip. In the clip μ\mu moves from 1 to 9 over 8 seconds, easing in and out, and both curves are traced as it goes, with a dot at the current μ\mu: 0.000651 at μ=3\mu=3, 0.00201 at 4, and its peak, 0.00292, at 5. Then the bell returns to 5 and the peak is marked; the logarithm is labelled a parabola. Your guess is a dotted line on the likelihood. Readouts give μ\mu, the likelihood to three significant figures and the log-likelihood to three decimals. After the clip a slider, “Centre μ”, moves μ\mu from 1 to 9 in steps of 0.1.

Slide the model, multiply the heights

I have data, and a model with a knob: here a bell of known width whose centre μ\mu I do not know. Each setting of the knob gives each data point a height. The idea of maximum likelihood is to choose the setting that makes the data I saw as probable as possible.

The heights multiply because the three points were drawn independently: the chance of seeing all three is a product. That product, as a function of the knob, is the likelihood:

L(θ)=∏k=1nf(xk;θ),L(\theta)=\prod_{k=1}^{n}f(x_k;\theta),

where f(x;θ)f(x;\theta) is the model’s density (or its pmf, for counts) at xx when the knob is set to θ\theta. The best setting, θ^\hat\theta, is the maximum likelihood estimate.

Before the clip you guessed where the peak would be. It is at μ=5\mu=5, the middle value, which is also the mean of the three. At μ=3\mu=3 the bell sits on the left point and gives the right point, 7, a low height; the product suffers. At μ=5\mu=5 no point is far from the centre.

Take the logarithm

Products of many small numbers are awkward: with 1000 data points the likelihood is smaller than any computer can store. Take the logarithm instead. It turns the product into a sum, and since the logarithm only ever rises, the peak stays at the same θ\theta:

ℓ(θ)=ln⁡L(θ)=∑k=1nln⁡f(xk;θ).\ell(\theta)=\ln L(\theta)=\sum_{k=1}^{n}\ln f(x_k;\theta).

This is the log-likelihood. For the bell of width 2,

ln⁡f(x;μ)=−(x−μ)28−ln⁡(22π),\ln f(x;\mu)=-\frac{(x-\mu)^2}{8}-\ln\big(2\sqrt{2\pi}\big),

so for the three points the log-likelihood is −38(μ−5)2-\tfrac38(\mu-5)^2 plus a constant: a parabola with its top at 5, the curve under the likelihood in the picture.

Three recipes

To find the peak, set the slope of ℓ\ell to zero.

A coin. hh heads in nn independent flips with chance pp of heads: ℓ(p)=hln⁡p+(n−h)ln⁡(1−p)\ell(p)=h\ln p+(n-h)\ln(1-p). Its slope is h/p−(n−h)/(1−p)h/p-(n-h)/(1-p), which is zero at

p^=hn.\hat p=\frac hn.

A bell. For bell-shaped data with unknown centre and width, the slopes give μ^=xˉ\hat\mu=\bar x, the sample mean, and

σ^2=1n∑k=1n(xk−xˉ)2,\hat\sigma^2=\frac1n\sum_{k=1}^{n}(x_k-\bar x)^2,

with divisor nn, so biased low, as Estimators: bias and variance showed. Maximum likelihood is not always unbiased.

Waiting times. For gaps t1,…,tnt_1,\dots,t_n from the exponential law of rate λ\lambda, ℓ(λ)=nln⁡λ−λ∑ktk\ell(\lambda)=n\ln\lambda-\lambda\sum_kt_k. Its slope n/λ−∑ktkn/\lambda-\sum_kt_k is zero at

λ^=n∑ktk=1tˉ,\hat\lambda=\frac{n}{\sum_kt_k}=\frac{1}{\bar t},

one over the mean gap.

A coin, and how sure to be

The likelihood also shows how sharply the data pin the parameter down.

Sharper with more flips

The likelihood of the flips against the chance of heads p.

Seven heads in ten flips. For each chance of heads p, the likelihood p⁷(1 − p)³ says how probable these flips are.

estimate p̂
0.7
standard error
0.1449
area under L
0.00076
Data
0.00 / 9.20 s
Describe this picture

One panel: the likelihood L(p)=p7(1−p)3L(p)=p^7(1-p)^3 of 7 heads in 10 flips, drawn against the chance of heads pp from 0 to 1, on a vertical axis counted in units of 10−310^{-3}. The clip traces the curve from p=0p=0 to 1, marks its peak at 0.7 with a dashed drop to the axis, then shades the area under it, labelled “1/1320 = 0.00076, not 1”. Readouts give the estimate p^\hat p, 0.7, its standard error, 0.1449, and the area under the curve, 0.00076. After the clip a switch, “Data”, changes the data to 70 heads in 100 flips. Its likelihood is about 10−2710^{-27}, so the vertical axis is relabelled in units of 10−2710^{-27}, and the caption says so. The peak stays at 0.7 and the curve becomes about three times narrower: standard error 0.0458, area 3.4×10−283.4\times10^{-28}.

The peak is at p^=0.7\hat p=0.7 in both cases. With 10 flips the curve is wide, so many values of pp fit nearly as well. With 100 flips it is narrow. Its width is measured by the standard error of p^\hat p,

p^(1−p^)n,\sqrt{\frac{\hat p(1-\hat p)}{n}},

0.14490.1449 for 10 flips and 0.04580.0458 for 100: ten times the data, a third of the width.

Watch out

The likelihood is not the probability that the parameter is right. It is a function of pp, but it is built from the chance of the data, and it does not add up to 1 over pp: the area under p7(1−p)3p^7(1-p)^3 is 1/13201/1320. Turning it into a probability for pp needs a starting belief, the subject of Bayesian updating.

Two properties make maximum likelihood a default way to fit a model. Under mild conditions on the model, as the sample grows, θ^\hat\theta closes in on the true value: it is consistent. And for large samples its distribution over repeated samples is close to a bell centred on the truth, with a width that shrinks like 1/n1/\sqrt n. I state these without proof.

Worked example

1. Seven heads in ten. At the estimate,

L(0.7)=0.77×0.33=0.002224,ℓ(0.7)=7ln⁡0.7+3ln⁡0.3=−6.1086.\begin{aligned} L(0.7)&=0.7^7\times0.3^3=0.002224,\\ \ell(0.7)&=7\ln0.7+3\ln0.3=-6.1086. \end{aligned}

A fair coin gives L(0.5)=0.510=0.000977L(0.5)=0.5^{10}=0.000977. So p^=0.7\hat p=0.7 makes the data 2.282.28 times as probable as a fair coin does: more probable, but not overwhelmingly.

2. The bell, with its width unknown too. For the data 3, 5 and 7, μ^=5\hat\mu=5. The squared deviations add to 8, so σ^2=8/3=2.667\hat\sigma^2=8/3=2.667 and σ^=1.633\hat\sigma=1.633. The sample variance of Describing data divides by 2 instead and gives s2=4s^2=4.

3. Waiting times. Four gaps between clicks, 0.2, 0.9, 0.4, 0.50.2,\ 0.9,\ 0.4,\ 0.5 s, add to 2.0 s. So λ^=4/2=2\hat\lambda=4/2=2 per second, the rate of the Geiger counter in Random arrivals. The log-likelihood ℓ(λ)=4ln⁡λ−2λ\ell(\lambda)=4\ln\lambda-2\lambda peaks there at 4ln⁡2−4=−1.22744\ln2-4=-1.2274.

4. Noise that is bell-shaped. If each measurement is a model value plus bell-shaped noise of fixed width, then −ℓ-\ell is, apart from a constant, ∑k(xk−μk)2/(2σ2)\sum_k(x_k-\mu_k)^2/(2\sigma^2). Making the likelihood largest is making the sum of squared errors smallest: maximum likelihood is least squares.

Try it yourself. Three heads in 12 flips give p^=3/12=0.25\hat p=3/12=0.25. A mean gap of 0.25 s gives λ^=4\hat\lambda=4 per second. If every data value is shifted by 10, the estimate of the bell’s centre shifts by 10.

Where you’ll meet this

Fitting models. Rates of events, failure times, the gain of a channel, the frequency of a tone in noise: many fitted parameters in science and engineering are maximum likelihood estimates, or close to them.

Classification. Logistic regression, the standard model for yes-or-no outcomes, is fitted by maximum likelihood.

Searching for a peak. Many estimates are found the way the picture found μ\mu: slide a template along, score each position, keep the best. Pitch trackers slide over candidate frequencies; radar slides over delays.

In signal processing · detection in noise

In bell-shaped white noise, the delay that maximises the likelihood of a known pulse is the delay where the correlation with the pulse peaks. That is what Matched filters and detection computes in the signal processing course.

Where this leads · least squares

The fourth example turns maximum likelihood into least squares. Least squares in the linear algebra course solves that problem with projections.

Reference card

QuantityFormulaNotes
LikelihoodL(θ)=∏kf(xk;θ)L(\theta)=\prod_kf(x_k;\theta)a function of θ\theta; not a probability for θ\theta
Log-likelihoodℓ(θ)=∑kln⁡f(xk;θ)\ell(\theta)=\sum_k\ln f(x_k;\theta)same peak
Coinp^=h/n\hat p=h/nstandard error p^(1−p^)/n\sqrt{\hat p(1-\hat p)/n}
Bellμ^=xˉ\hat\mu=\bar x, σ^2=1n∑k=1n(xk−xˉ)2\hat\sigma^2=\frac1n\sum_{k=1}^{n}(x_k-\bar x)^2divisor nn: biased low
Exponentialλ^=n/∑ktk=1/tˉ\hat\lambda=n/\sum_kt_k=1/\bar tone over the mean gap
Bell-shaped noisemaximum likelihood = least squares
Large samplesconsistent, close to a bellwidth like 1/n1/\sqrt n

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look