1.1 The likelihood function

In this section we introduce the likelihood function, the tool we will use in this chapter for doing inference. Let us begin with a simple example.

Imagine that we toss a coin with an unknown probability \(p\) of landing on heads. Each time the coin lands on heads we record a 1 and each time it lands on tails a 0. We repeat the experiment 10 times and observe the sequence:

##  [1] 0 0 1 0 0 1 0 1 0 0

We can calculate the probability of observing this exact sequence. The probability of observing 1 is \(p\) and of observing 0 is \(1-p\). Since the observations are independent, the total probability will be the product of each probability and so the probability is \[ p^3(1-p)^7. \]

We can think of this as a function of \(p\) that tells us the probability of observing what we actually observed. For example, if \(p=0.4\) the probability is \(1.79 \cdot 10^{-3}\), or if \(p=0.5\) the probability is \(9.77 \cdot 10^{-4}\).

The principle that we will follow to estimate parameters is that since \(p=0.4\) gives a higher probability to our observation than \(p=0.5\) we will prefer \(0.4\) over \(0.5\) as an estimate of \(p\).

We call this function the likelihood function and denote it \(L\). That is

\[ L(p) := p^3(1-p)^7. \]

## Warning: package 'ggplot2' was built under R version 4.6.1
Likelihood of the sample

Figure 1.1: Likelihood of the sample

In the picture we see that the likelihood function attains its highest value at \(p=0.3\). Using the above principle, we therefore prefer \(0.3\) as an estimate of \(p\) over any other value. This is the maximum likelihood estimate (MLE) of \(p\).

Let us define the likelihood function in general. We have a parametric model of our observations, that is we assume that we observe random variables that are independent identically distributed, with a probability function (or density) \(p_\theta(x)\). Here \(\theta\) is an unknown parameter. For a random sample \(x_1,\ldots , x_n\) of size \(n\) the likelihood function is

\[ L_n(\theta) = \prod_{i=1}^n p_\theta(x_i). \]

That is, the likelihood is the probability (or density) of our observation, as a function of the unknown parameter.

As a second example, say that we observe random variables \(X_i\) that are iid \(\mathsf N(\mu,\sigma^2)\), where \(\mu\) and \(\sigma^2\) are unknown parameters. In other words, the joint density of an iid sample is \[ p(x_1,\ldots, x_n) = \prod_{i=1}^n \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{1}{2\sigma^2}(x_i-\mu)^2}. \] The likelihood function is then \[ L_n(\mu,\sigma^2) = \prod_{i=1}^n \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{1}{2\sigma^2}(x_i-\mu)^2}. \] That is, the density and the likelihood function are written using the same formulas, but the density is a function of \(x_i\), while the likelihood is a function of the unknown parameters \(\mu\) and \(\sigma^2\).