Understanding Maximum Likelihood
An Interactive Visualization
Created by Kristoffer Magnusson
The maximum likelihood method is used to fit many models in statistics. In this post I will present some interactive visualizations to try to explain maximum likelihood estimation and some common hypotheses tests (the likelihood ratio test, Wald test, and Score test).
We will use a simple model with only two unknown parameters: the mean and variance. Our primary focus will be on the mean and we'll treat the variance as a nuisance parameter.
Before we do any calculations, we need some data. So, here's 10 random observations from a normal distribution with unknown mean and variance.
Y = [1.0, 2.0]
Now we need to find what combination of parameter values maximize the likelihood of observing this data. Try moving the sliders around.
We can calculate the joint likelihood by multiplying the densities for all observations. However, often we calculate the log-likelihood instead, which is
The combination of parameter values that give the largest log-likelihood is the maximum likelihood estimates (MLEs).
Finding the Maximum Likelihood Estimates
If we repeat the above calculation for a range of parameter values, we get the plots below. (The function could be plotted as a three-dimensional hill as well). We can find the top of each curve by using the partial derivatives with regard to the mean and variance, which is generally called the score function (U). In this case we can solve the score equation analytically (i.e. set it to zero and solve for the mean and variance). We can also solve this equation by brute force simply by moving the sliders around until both partial derivatives are zero (hint: find the MLE for the mean first).
After we've found the MLEs we usually want to make some inferences, so let's focus on three common hypothesis tests. Use the sliders below to change the null hypothesis and the sample size.
The score function evaluated at the null is,
The observed Fisher information is the negative of the second derivative. This is related to the curvature of the likelihood function -- try increasing the sample size and note that the peak gets narrower around the MLE and that the information increases. The inverse of I is also the variance of the MLE.
We have the following null and alternative hypothesis,
The likelihood ratio test compares the likelihood ratios of two models. In this example it's the likelihood evaluated at the MLE and at the null. This is illustrated in the plot by the vertical distance between the two horizontal lines. If we multiply the difference in log-likelihood by -2 we get the statistic,
Asymptotically LR follow a distribution with 1 degrees of freedom, which gives p = NaN.
Note: The figure is simplified and do not account for the fact that each likelihood is based on different variance estimates.
What are the formulas?
This page is still under construction, formulas will be added later.
How do I cite this page?
Cite this page according to your favorite style guide. The page is created by Kristoffer Magnusson, and you can find the current version number and the date of the last update in the footer.
I found a bug/error/typo or want to make a suggestion!
I'm gonna ask a large number of students to visit this site. Will it crash your server?
No, it will be fine. The app runs in your browser so the server only needs to serve the files.
Can I include this visualization in my book/article/etc?
Yes, go ahead! The design of the visualizations on this page is dedicated to the public domain, which means "you can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission" (see Creative common's CC0-license). Although, attribution is not required it is always appreciated!.
There are many ways to contribute to free and open software. If you like my work and want to support it you can:
Finacial support is not the only way to contribute. Other ways to contribute is to suggest new features, contribute useful references, or help fix typos. Just open a issues on GitHub.
I've created some posters inspired by my interactive visualizations. You can find them on my Etsy shop.