TL;DR
A model of some data has one or more unknown settings, called parameters. The likelihood function takes the data as fixed and asks, for each possible setting, how probable the observed data would be if that setting were true. The result is a curve or surface over the parameters, not over the data. Its highest point is the setting that best explains what was seen.
The likelihood is the bridge between a model and a dataset. It is the object that maximum likelihood maximises and that Bayesian updating multiplies by a prior.
Where you'll see it: in fitting a Gaussian to measurements, in estimating a coin's bias from flips, and in the loss function of nearly every probabilistic model trained on data.
Intuition
Same formula, different question
Start with a familiar question. Flip a coin ten times and get seven heads. A probability question asks: if the coin's heads chance is 0.5, how likely are seven heads? The answer is a number, about 0.117. An inference question turns this around: the seven heads are known, so which heads chance would make them most plausible?
The formula is the same in both cases. Only the role of each piece changes. In the probability question the chance is fixed and the outcome varies. In the likelihood question the outcome is fixed and the chance varies. The likelihood function is that second reading.
Scoring candidates
Take a few candidate values of the heads chance : 0.1, 0.5 and 0.7. Under each one, the same observed data gets a different probability. Under 0.1, seven heads in ten flips is nearly impossible. Under 0.5, it is unusual but possible. Under 0.7, it is the most natural outcome. The likelihood simply records these scores for every candidate, and the candidate with the largest score is the best explanation.
The name is chosen carefully. "Likely" describes the data under a setting, so the likelihood is a measure of how well each setting explains the observations. It is not a probability that the setting is true. That distinction is the main source of confusion, and we will return to it.
flowchart LR A[Observed data, held fixed] --> B[Candidate parameter theta] B --> C[Probability of the data under theta] C --> D[Likelihood of theta] D --> E[Compare across all candidates]
The math
Definition
Suppose the data are and the model says each observation comes from a distribution with density , where is the parameter. For a discrete model, is a probability mass function instead. The data are assumed to be independent, so their joint probability is a product.
For fixed observed data , the likelihood of a parameter value is
Here is the variable and the data are constants. The joint density of the data, viewed as a function of for a fixed , is the same expression; we only change which argument we vary.
Two rules follow directly from this definition.
- Only the ratio of likelihoods between two parameter values carries meaning. Multiplying by any constant that does not depend on leaves all comparisons unchanged.
- The likelihood does not integrate or sum to 1 over in general. It is not a probability distribution over the parameters.
The log-likelihood
Products of many numbers below 1 become tiny, and a computer may round them to zero. So we almost always work with the logarithm:
The logarithm is increasing, so the that maximises also maximises . It also turns the product into a sum, which is easier to differentiate. The Logarithm is used only for this convenience; it does not change which parameter is best.
Worked form: the coin
For flips (each a Bernoulli trial, so follows a binomial) with heads and heads chance , each flip contributes or , so
The binomial coefficient is left out because it does not depend on (rule 1 above). The curve for seven heads in ten flips peaks at and is already quite wide, so many nearby chances remain plausible.
- L(p), 7 heads in 10 flips
Worked form: a Gaussian
For observations from , with ,
The likelihood is a surface over . Its shape tells you which pairs of values are consistent with the data.
Worked examples
Observe H, T, H, so and . The likelihood is .
- Try : .
- Try : .
- Try : .
- The largest of these three is at . To find the exact peak, set the Derivative of to zero: , which gives .
Interpretation: among these heads chances, two-thirds explains "two heads in three" best. The likelihood rules out as a poor explanation, but it does not say is the true value.
Four observations are 2, 4, 6 and 8. Assume they come from a Gaussian with unknown mean and variance .
- Write the log-likelihood: .
- Differentiate with respect to and set to zero: , so .
- Compute the squared deviations from 5: , summing to 20.
- Differentiate with respect to and set to zero: , where and . So .
- Take the square root for the standard deviation: .
Interpretation: the likelihood peaks at mean 5 and variance 5. The divisor is , not , which makes this variance estimate slightly too small on average. That bias is a known feature of the maximum likelihood answer for the variance.
A sensor reads a fixed voltage five times: 9.8, 10.1, 10.3, 9.9 and 10.4. Assume the readings are independent Gaussians with unknown mean and variance.
- The sum is , so the mean estimate is .
- The deviations from 10.1 are . Their squares are , summing to .
- The variance estimate is , so .
- To compare with a rival setting such as , the log-likelihood difference is . The sum equals in this case, so the difference is . The likelihood ratio is , about 2200 to 1 in favour of .
Interpretation: the data overwhelmingly favour a mean near 10.1 over 10.5. This comparison holds the variance fixed at its estimate. The likelihood ratio (see Log-Likelihood Ratio) is a direct way to compare two settings, and it needs no prior.
Tradeoffs and failure modes
The likelihood is only as good as the model behind it. When the model family is wrong, the highest likelihood setting can still be the best of a bad set.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Observations are not independent | The product in the likelihood double counts information | Use a model that includes the dependence, such as a time series or hierarchical model |
| The model family is misspecified | The best setting explains the data poorly | Check residuals, or compare several model families |
| Few data points | The likelihood is flat, and many settings look similar | Report the whole likelihood curve, not only its peak |
| Parameters are on the boundary | Derivatives may not be zero at the best point | Check the boundary values directly |
A practical point: always inspect the shape of the likelihood, not only its maximum. A sharp peak says the data pin the parameter down. A flat one says they do not.
History
The idea of comparing hypotheses by how well they predict observed data goes back to the eighteenth century, but the term "likelihood" as a technical concept distinct from probability was developed by the statistician R. A. Fisher in the 1920s. He argued that the likelihood, not the probability of a parameter, should drive inference when the parameter is unknown. The approach caught on because it gives a single, mechanical recipe for estimation and testing across many models. Later work on the likelihood ratio, which compares two settings directly, made it central to hypothesis testing.
Recap
The likelihood function fixes the observed data and varies the parameter. Its value at each candidate records how well that candidate explains what was seen. Working with its logarithm turns products into sums without changing the best candidate. Maximising the likelihood gives maximum likelihood estimates. Multiplying the likelihood by a prior and normalising gives the posterior distribution, so the likelihood is the piece of evidence that every Bayesian update uses.
Check yourself
QuestionRecall: in the likelihood function, which quantity is held fixed and which one varies?Show answer
The observed data are held fixed, and the parameter varies over its possible values. This is the opposite of a probability density, where the parameter is fixed and the outcome varies.
QuestionComputation: a coin shows four heads in five flips. Compare the likelihood of heads chance with that of . Which is larger, and by what ratio?Show answer
The likelihood is . At it is . At it is . The ratio is , so explains the data about 2.6 times better.
QuestionWhy is the likelihood not a probability distribution over the parameter, even though it is built from probabilities?Show answer
Its values do not need to sum or integrate to 1 across parameter values. It measures how well each parameter explains fixed data, not how likely each parameter is. Turning it into a distribution over parameters requires a prior and normalisation, which is the posterior step.
QuestionApplied: a student multiplies two thousand probabilities, each about 0.5, and the computer prints 0. What is the fix, and why does it not change the best parameter?Show answer
Compute the sum of logarithms instead of the product. Each log is around minus 0.7, so the sum is about minus 1,390, which is easily representable (the product, about , is smaller than the smallest number a standard double-precision float can hold). The logarithm is increasing, so the parameter that maximises the product also maximises the sum of logs.
Sources
- Likelihood function (Wikipedia)
- Maximum likelihood estimation (Wikipedia)
- Bishop, Pattern Recognition and Machine Learning, §1.2.5: https://www.microsoft.com/en-us/research/publication/pattern-recognition-machine-learning/