Lecture 19 The EM Algorithm
For the standard families of tables 1.1 and 1.2 the likelihood equation from lecture 5 could be solved in closed form, but for models with latent variables or missing data, as considered in this lecture, this is no longer the case. The expectation-maximisation (EM) algorithm, introduced in this lecture, alternates between filling in the missing information and re-estimating the parameter values. We prove that each round of the EM algorithm cannot decrease the likelihood. We illustrate the EM algorithm with the help of a worked example, considering a mixture of two normal distributions. This example also gives the non-identifiable model from lecture 4. In lecture 21 we will discuss how to implement the EM algorithm in R.
19.1 Incomplete Data
Assume that we are given data consisting of i.i.d. pairs , , with joint density or joint probability weights , but we have observed only . The pair with is called the complete data, the values are called the observed data and the unobserved values are called latent variables. The complete-data log-likelihood is given by
and the observed-data log-likelihood is given by the marginal density of a single observation,
where the integral is used instead of a sum when is continuous. The MLE for is the maximiser of , but the algebra from lecture 5 is not applicable, since the sum inside the logarithm prevents any simplifications. The function , being a sum of standard log-likelihoods, would be easy to maximise, but it cannot even be evaluated as it depends on . The EM algorithm is based on this observation.
In the example we consider in the lecture, the population consists of two groups, with proportion for group 1 and for group 2. The measurement for group 1 is and for group 2 is , where we assume that we know . We are given observations of the measurement , but we do not know which group the observation belongs to. If we write for the density of , then the observations are i.i.d. with density
This is an example of a two-component normal mixture. If we knew the groups, the MLEs for this example would be easy to find: we would get the proportion of group 1 and the two group means by using examples 5.3 and 5.4, but without the groups we cannot find the MLEs in closed form.
19.2 The Algorithm
If we knew the parameter, we could compute the conditional distribution of the latent variables given the data; if we knew the latent variables, we could maximise . Neither of these quantities is known, so we start with a guess and alternate between filling in the missing values, replacing by its conditional expectation given the observed data, and maximising over .
Let be given. Then the EM algorithm for finding the parameter values consists of the following iterative steps for :
-
(E)
Expectation step: compute
the conditional expectation of the complete-data log-likelihood given the observed data, where the conditional distribution of is computed using the parameter value .
-
(M)
Maximisation step: set
The second argument of enters only through the conditional distribution of given . By Bayes’ rule, proposition A.20 in appendix A, this conditional distribution has density or probability weights
Since the pairs are independent, once the data are observed is a sum over the observations, given by
In cases where is linear in the indicator functions of the latent variables, e.g. for the mixture distribution considered in this section, the E-step is to replace the indicator functions by the corresponding conditional probabilities given the data.
19.3 The Ascent Property
The algorithm only ever maximises , and it is not obvious that this does anything for the observed-data log-likelihood . The central result of this lecture is that it does. We assume throughout that the set of values with does not depend on , the analogue for the latent variables of condition (R2) in definition 16.1. We also assume that for every data point and every , and that is finite for all and every data point , so that and in the decomposition (19.1) below are well defined. Rearranging the formula for and taking logarithms, we have
for every such . The left-hand side does not involve and thus taking conditional expectations given under , with the random variable in place of , does not change this. Summing over the sample gives the decomposition
valid for all .
Let be generated by the EM algorithm from definition 19.1. Then
We first show that for all . Since is a sum over the observations, we only need to consider a single observation with observed value . Let . This value is well defined and positive by our assumption on the supports. Since is convex, we can use Jensen’s inequality, lemma A.7, for the conditional distribution of given under to get
since is a probability distribution over (with sums replaced by integrals for a continuous latent variable). This is the same argument as in the proof of theorem 16.2.
Now we can use the decomposition (19.1) at and at , both with the same second argument , and taking the difference we get
The first bracket is non-negative, since is the maximiser of in the M step, and the second bracket is non-positive by the first step of the proof. Thus the difference is non-negative as claimed. ∎
The statement of the theorem does not imply that EM finds the MLE: the sequence converges whenever is bounded above, but the iteration may stop at a local maximum or, in principle, at a saddle point. In general we can only say that the points where the EM algorithm converges are stationary points of .
Let be open and as well as differentiable for all . Then
In particular, if for some , the point is a root of the likelihood equation .
From (19.1) we know that the function is differentiable. Furthermore, from the first step of the proof of theorem 19.2 we know that this function has its maximum at an interior point . Thus, the derivative at this point must be zero. Taking derivatives of the decomposition at gives the identity. If , then is an interior maximiser of and the right-hand side equals zero at . Thus we have . This completes the proof. ∎
For a vector parameter the same argument applies, but now using gradients instead of derivatives. Conversely, if the function is strictly concave for all , then all roots of the likelihood equation are fixed points: The derivative of is zero at a root and the only maxima of a strictly concave function are the points where the derivative is zero; exercises 19.2 and 19.4 show that this argument applies for two mixtures.
19.4 A Two-Component Normal Mixture
We can apply the algorithm for finding the parameters of a mixture from section 19.1. The E and M steps for this mixture model are as follows.
Let be i.i.d. with and and given let , where is known and is unknown. Then the complete-data density is and . Thus, the complete-data log-likelihood is
which is linear in the indicators. For the E step, using Bayes’ rule with the current value , we find
This is called the responsibility of group 1 for the observation , and is with replaced by and replaced by .
For the M step we maximise over with the fixed. Since , the partial derivatives of are
and setting these to zero gives the updates
The second derivatives are negative and thus these are maxima. They are the complete-data MLEs of examples 5.3 and 5.4 with indicators replaced by responsibilities.
For a numerical example we can choose , together with the observations and initial value . In this case we have and to cancel the weights we divide the numerator and denominator by to get
So, with four decimal digits we have
This shows that the two small observations are assigned nearly completely to group 1, while the three large observations are assigned to group 2. Now, with , and , we can use the update (19.2) to get
The log-likelihood of the observed data increases from to , as required by theorem 19.2 (see exercise 19.3). For another iteration we find
At this point the iteration no longer changes by more than four decimal digits: the responsibilities are so close to or that the mean of each group coincides with the mean of the observations for that group. The algorithm converged quickly in this example, because the groups were well separated. In cases where the groups have more overlap, more iterations will be required for the algorithm to converge.
In the example we assumed that the variance was known and common to both groups. If, on the other hand, we had assumed separate, unknown variances for the two groups, then the estimate for one component could be centred on an observation and the variance of this component could be shrunk to zero. In this case, the likelihood would become infinite at this point and the MLE would not exist.
19.5 Practical Matters
Three issues arise whenever EM is used, and the mixture shows all three. The first is the promised failure of identifiability: the parameter values and give the same density , and thus the model is not identifiable in the sense of definition 4.10, the difficulty foreshadowed after example 4.11. This is called label switching: the likelihood has two global maxima which are mirror images of each other, and EM started from instead of in example 19.4 converges to instead of . Either answer is fine on its own, but averaging different runs is not, and the remedy of lecture 4 is to restrict the parameter space by a convention such as . The second issue is local maxima: theorem 19.2 guarantees ascent and nothing more, and a poor starting value can lead the iteration to a local maximum of without warning. The standard precaution is to run EM from several starting values and to keep the run with the largest observed-data log-likelihood, which we can always evaluate. The third issue is when to stop: since is non-decreasing, we stop when its increase falls below a small tolerance; convergence is geometric. Finally, EM produces an estimate but no standard error; that is obtained afterwards from the observed information at the fixed point, as in section 17.3. Lecture 21 shows all three issues in R.
-
•
In an incomplete-data model, the complete data has an easy log-likelihood , but only is observed and the observed-data log-likelihood has a sum inside the logarithm.
-
•
EM iteratively computes the expectation and then maximises the expectation over .
-
•
We have shown that for all . The proof uses and Jensen’s inequality to show that the maximum of is attained at . A fixed point of the iteration is a root of the likelihood equation.
-
•
For a two-component normal mixture, the E step computes the responsibilities and the M step computes the weight as the average responsibility and the means as the responsibility- weighted mean of the data.
-
•
Mixture parameters are only identifiable up to relabelling the components (label switching). Local maxima of the likelihood function can be avoided by running EM with different starting values and by comparing runs of the algorithm using the observed-data log-likelihood.
Suppose and are two known, distinct densities, and that are i.i.d. with density
where is the only unknown parameter. Let be the component observation belongs to, as in example 19.4.
-
1.
Write down the observed-data log-likelihood and the likelihood equation .
-
2.
Write down the complete-data log-likelihood and show that the E step determines the responsibilities and the M step determines the update .
-
3.
Show that and thus that . Deduce that is a fixed point of the EM iteration if and only if it solves the likelihood equation, as in proposition 19.3.
For the data, starting value and first iterate of the numerical illustration in example 19.4, compute the observed-data log-likelihood for and . Show that the likelihood has increased. Which of the five observations contributes most to the increase in likelihood? Why?
Consider the two-component normal mixture from example 19.4, but with known weight and known variance . The only unknown quantities are the means .
-
1.
Show that the EM updates for this case are given by the two mean updates from (19.2), where the responsibilities are computed using the known .
-
2.
Compute the derivative of the observed-data log-likelihood and show that
where is the responsibility at . Deduce that the likelihood equations coincide with the fixed-point equations of the EM iteration.
-
3.
What are the updates in the limit ? Comment upon your result in the context of example 5.4.