Introduction to Maximum likelihood
And you may wonder : what is Maximum Likelihood? Why is it used here and what is it’s role? You are right to question this because Maximum Likelihood is one of the most used, yet misunderstood, algorithm nowadays. It is often present in the background of your statistical tests without you ever knowing it. In this article, I will explain how this algorithm work, so you better understand what is going one under the hood of your models!
Introduction
One of the fundamental goals of statistics is to estimate models that best explain models of the world. The world is often so complex, and the best way we can infer phenomenon is to make an approximation of them. Models that we made, such as linear regression, have parameters which tells us how the variables and covariables influence our model.
Once we have collected data, we need a principled way to determine which parameter values make our model most consistent with the observations.
This is where the concept of likelihood becomes essential. To understand Maximum likelihood, we have to understand what is likelihood first.
Likelihood
Likelihood refers to how well a sample provides support for particular values of a parameter in a model. In other words, it is the product of the probability distribution evaluated at each datapoints :
The idea is that we want to know which value of θ makes the observed data most probable. In other words, we want to find the parameter values of the probability distribution that best fit the observed data, and the likelihood function tells us how plausible the data are under different choices of θ.
And then… you probably guessed it, but Maximum likelihood aims to tell us which parameter (x1, x2,…. xn) maximises the likelihood of finding θ! The goal is to find the parameters of the distribution that will best fit the data in front of you. Here is an example of a graph that shows how it words.
In this example, we are trying to fit a Parametric Density Function (PDF) to our data using Maximum likelihood. A parametric density function is a mathematical function that describes the probability distribution of a continuous random variable. With Maximum Likelihood, we are trying a bunch of different distribution to see which one has the best set of parameters to estimate our current sample.
Now that we understand the broad idea of maximum likelihood, let’s dive into the maths behind this test.
Mathematical understanding
Likelihood formula
Suppose that we have data (x1, x2,…. xn) estimated by a parameter theta (θ)
When we multiply the probability of each data of our distribution given θ, we get the joint probability density of this dataset. A joint probability distribution essentially tells us the probability that two or more random variables occur simultaneously.
The likelihood we defined earlier does the opposite as the joint probability density. Instead of predicting our data (x1, x2, x3, etc…) given our parameter it tries to predict our parameter θ given our data x! So we switch over the formula (from p(x | θ) to p(θ | x) :
The joint probability density tells us how probable the observed data are for a fixed parameter value. The likelihood function uses the same mathematical expression, but now the data are fixed and the parameter varies. Both formula have a similar outcome, but different ways to achieve it :
In essence, these test can answer these types of questions :
“Joint probability density formula : If θ is the true parameter, what is the probability of seeing this sample?”
“Likelihood formula : Given the sample we observed, how plausible is each possible value of θ?”
That’s the nuance here!
Arg max
Now that we have defined the likelihood function, we can introduce Maximum Likelihood, which seeks the parameter value that makes the observed data most probable.
“Arg max” stands for argument of the maximum, meaning the value of the variable at which a function reaches its maximum. We often take the logarithm of the likelihood to obtain the log-likelihood, which simplifies calculations. Since the logarithm is a strictly increasing function, the value that maximizes the log-likelihood is the same value that maximizes the likelihood itself.
To apply a maximum likelihood estimator, we begin by writing the log‑likelihood of the data given the parameters. We then choose the parameter values that maximize this log‑likelihood function. There are many possible ways to compute this argmax (it’s different for each probability density distribution!). Because each probability distribution has its own parameters, each one leads to a different log‑likelihood expression.
To make everything we just learned more concrete, we will now work through an example using the normal distribution and show exactly how the maximum likelihood estimate is derived.
Maximum likelihood with a Normal Distribution
Firstly, we make the assumption that our data are identically distributed, which essentially means that our observation are independant and identically distributed (to read more about the statistical assumption of Maximum Likelihood and it’s properties, you can read this article). As you may know, a normal distribution contains two parameters, which are :
- Mean (μ): This is the location parameter that determines the center of the distribution.
- Standard Deviation (σ): This is the scale parameter that determines the width of the distribution.
The Probability Density Function of a normal distribution is :
So it’s log likelihood will be :
Remember here, we juste switched from p(x | μ,σ) to p(μ,σ | x) so that instead of predicting our data (x1, x2, x3, etc…) given our parameter (μ,σ) we try to predict our parameter (μ,σ) given our data!
To find which values of μ and σ make our data most likely, we need to look for the peak of the log-likelihood curve. To do this, we have to use differentiation as our mathematical tool. A function reaches its maximum at the point where its slope becomes zero. So, by taking the derivative of the log-likelihood with respect to each parameter for the log-likelihood formula and setting it equal to zero, we can find the parameter values that produce the highest likelihood.
Differentiate with respect to μ
We take the derivative of the log-likelihood with respect to μ :
Set it equal to zero :
Solve :
And there you go! This final formula estimates the data that is most likely given our parameters. But wait…. that looks like the formula for the mean! That is because if our distribution is normal, the value of μ that best explains the data we see is the average of the population. Let’s see now what will be the final formula that best estimates σ.
Differentiate with respect to σ
Here are the steps to obtain the formula that best estimate σ in our distribution. We first have to differentiate the log-likelihood:
Set it equal to 0 :
Multiply by σ³ :
Solve for σ² :
This awfully looks like the formula for the variance isn’t it? That is because it it! In a normal distribution, combined with the mean, the parameter value of the variance that makes our data most likely is the average squared deviation from the sample mean.
Final result
By doing all these differentiations, we obtain the formula that best estimate the parameters that makes our data most likely. In essence, we are choosing the normal curve (with μ and σ) amongst all possible normal curve that is the most consistent with the data that we observe. By carrying out the differentiation of μ and σ, we obtained formulas that identify the parameter estimates that are the most consistent with our observation!
Conclusion
Maximum likelihood is a complex algorithm used in many different areas of statistics and machine learning. In this article, we went through the logic of this algorithm, it’s mathematical basis as well as an example of it’s application with an normal distribution. Thanks to softwares, we don’t need to calculate all these parameters, but it is still good to understand what is going on under the hood.
There is still much more to explore about Maximum Likelihood, including its assumptions, theoretical properties, and how it applies to different probability distributions. Furthermore, there are also other alternative (such as Restricted Maximum Likelihood) that I didn’t present because they go beyond the scope of this introduction. Regardless, this overview provides you with a good starting point for understanding how Maximum Likelihood works and why it is so widely used


