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 (Xi,Zi)(X_{i},Z_{i}), i=1,…,ni=1,\dots,n, with joint density or joint probability weights fc⁢(x,z;θ)f_{c}(x,z;\theta), but we have observed only X=(X1,…,Xn)X=(X_{1},\dots,X_{n}). The pair (X,Z)(X,Z) with Z=(Z1,…,Zn)Z=(Z_{1},\dots,Z_{n}) is called the complete data, the values XX are called the observed data and the unobserved values ZiZ_{i} are called latent variables. The complete-data log-likelihood is given by

ℓc⁢(θ)=∑i=1nlog⁡fc⁢(Xi,Zi;θ),\ell_{c}(\theta)=\sum_{i=1}^{n}\log f_{c}(X_{i},Z_{i};\theta),

and the observed-data log-likelihood is given by the marginal density of a single observation,

f⁢(x;θ)=∑zfc⁢(x,z;θ),ℓ⁢(θ)=∑i=1nlog⁡f⁢(Xi;θ),f(x;\theta)=\sum_{z}f_{c}(x,z;\theta),\qquad\ell(\theta)=\sum_{i=1}^{n}\log f(% X_{i};\theta),

where the integral is used instead of a sum when ZiZ_{i} is continuous. The MLE for θ\theta is the maximiser of ℓ\ell, but the algebra from lecture 5 is not applicable, since the sum inside the logarithm prevents any simplifications. The function ℓc\ell_{c}, being a sum of standard log-likelihoods, would be easy to maximise, but it cannot even be evaluated as it depends on ZZ. The EM algorithm is based on this observation.

In the example we consider in the lecture, the population consists of two groups, with proportion π\pi for group 1 and 1−π1-\pi for group 2. The measurement for group 1 is N⁢(μ1,σ2)N(\mu_{1},\sigma^{2}) and for group 2 is N⁢(μ2,σ2)N(\mu_{2},\sigma^{2}), where we assume that we know σ2\sigma^{2}. We are given observations of the measurement XiX_{i}, but we do not know which group Zi∈{1,2}Z_{i}\in\{1,2\} the observation belongs to. If we write φσ\varphi_{\sigma} for the density of N⁢(0,σ2)N(0,\sigma^{2}), then the observations are i.i.d. with density

f⁢(x;θ)=π⁢φσ⁢(x−μ1)+(1−π)⁢φσ⁢(x−μ2),θ=(π,μ1,μ2)∈(0,1)×ℝ×ℝ.f(x;\theta)=\pi\,\varphi_{\sigma}(x-\mu_{1})+(1-\pi)\,\varphi_{\sigma}(x-\mu_{% 2}),\qquad\theta=(\pi,\mu_{1},\mu_{2})\in(0,1)\times\mathbb{R}\times\mathbb{R}.

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 ℓc\ell_{c}. Neither of these quantities is known, so we start with a guess θ0\theta_{0} and alternate between filling in the missing values, replacing ℓc\ell_{c} by its conditional expectation given the observed data, and maximising over θ\theta.

Definition 19.1.

Let θ0∈Θ\theta_{0}\in\Theta be given. Then the EM algorithm for finding the parameter values θ1,θ2,…\theta_{1},\theta_{2},\dots consists of the following iterative steps for k=0,1,2,…k=0,1,2,\dots:

  1. (E)
    ​

    Expectation step: compute

    Q⁢(θ|θk)=𝔼θk⁢(ℓc⁢(θ)|X),Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k})=\mathbb{E}_{\theta_{k}}\bigl{(}% \ell_{c}(\theta)\!\mathrel{\big{|}}\!X\bigr{)},

    the conditional expectation of the complete-data log-likelihood given the observed data, where the conditional distribution of ZZ is computed using the parameter value θk\theta_{k}.

  2. (M)
    ​

    Maximisation step: set

    θk+1=arg⁡maxθ∈Θ⁡Q⁢(θ|θk).\theta_{k+1}=\arg\max_{\theta\in\Theta}Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta% _{k}).

The second argument θk\theta_{k} of QQ enters only through the conditional distribution of ZZ given XX. By Bayes’ rule, proposition A.20 in appendix A, this conditional distribution has density or probability weights

k⁢(z|x;θ)=fc⁢(x,z;θ)f⁢(x;θ).k(z\mskip 1.0mu|\mskip 1.0mux;\theta)=\frac{f_{c}(x,z;\theta)}{f(x;\theta)}.

Since the pairs (Xi,Zi)(X_{i},Z_{i}) are independent, once the data are observed Q⁢(θ|θk)Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k}) is a sum over the observations, given by

Q⁢(θ|θk)=∑i=1n∑zk⁢(z|xi;θk)⁢log⁡fc⁢(xi,z;θ).Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k})=\sum_{i=1}^{n}\sum_{z}k(z\mskip 1% .0mu|\mskip 1.0mux_{i};\theta_{k})\,\log f_{c}(x_{i},z;\theta).

In cases where ℓc\ell_{c} 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 QQ, and it is not obvious that this does anything for the observed-data log-likelihood ℓ\ell. The central result of this lecture is that it does. We assume throughout that the set of values zz with fc⁢(x,z;θ)>0f_{c}(x,z;\theta)>0 does not depend on θ\theta, the analogue for the latent variables of condition (R2) in definition 16.1. We also assume that f⁢(x;θ)>0f(x;\theta)>0 for every data point xx and every θ∈Θ\theta\in\Theta, and that 𝔼θ′⁢(log⁡fc⁢(x,Z;θ)|X=x)\mathbb{E}_{\theta^{\prime}}\bigl{(}\log f_{c}(x,Z;\theta)\!\mathrel{\big{|}}% \!X=x\bigr{)} is finite for all θ,θ′∈Θ\theta,\theta^{\prime}\in\Theta and every data point xx, so that Q⁢(θ|θk)Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k}) and H⁢(θ|θk)H(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k}) in the decomposition (19.1) below are well defined. Rearranging the formula for k⁢(z|x;θ)k(z\mskip 1.0mu|\mskip 1.0mux;\theta) and taking logarithms, we have

log⁡f⁢(x;θ)=log⁡fc⁢(x,z;θ)−log⁡k⁢(z|x;θ)\log f(x;\theta)=\log f_{c}(x,z;\theta)-\log k(z\mskip 1.0mu|\mskip 1.0mux;\theta)

for every such zz. The left-hand side does not involve zz and thus taking conditional expectations given X=xX=x under θk\theta_{k}, with the random variable ZZ in place of zz, does not change this. Summing over the sample gives the decomposition

equation (19.1) (19.1)
ℓ⁢(θ)=Q⁢(θ|θk)−H⁢(θ|θk),where ⁢H⁢(θ|θk)=∑i=1n𝔼θk⁢(log⁡k⁢(Zi|Xi;θ)|Xi),\ell(\theta)=Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k})-H(\theta\mskip 1.0mu% |\mskip 1.0mu\theta_{k}),\qquad\text{where }H(\theta\mskip 1.0mu|\mskip 1.0mu% \theta_{k})=\sum_{i=1}^{n}\mathbb{E}_{\theta_{k}}\bigl{(}\log k(Z_{i}\mskip 1.% 0mu|\mskip 1.0muX_{i};\theta)\!\mathrel{\big{|}}\!X_{i}\bigr{)},

valid for all θ,θk∈Θ\theta,\theta_{k}\in\Theta.

Theorem 19.2.

Let θ0,θ1,θ2,…\theta_{0},\theta_{1},\theta_{2},\dots be generated by the EM algorithm from definition 19.1. Then

ℓ⁢(θk+1)≥ℓ⁢(θk)for all k=0,1,2,…\ell(\theta_{k+1})\geq\ell(\theta_{k})\qquad\text{for all $k=0,1,2,\dots$}
Proof.

We first show that H⁢(θ|θk)≤H⁢(θk|θk)H(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k})\leq H(\theta_{k}\mskip 1.0mu|% \mskip 1.0mu\theta_{k}) for all θ\theta. Since HH is a sum over the observations, we only need to consider a single observation with observed value xx. Let Y=k⁢(Z|x;θ)/k⁢(Z|x;θk)Y=k(Z\mskip 1.0mu|\mskip 1.0mux;\theta)/k(Z\mskip 1.0mu|\mskip 1.0mux;\theta_{% k}). This value is well defined and positive by our assumption on the supports. Since −log-\log is convex, we can use Jensen’s inequality, lemma A.7, for the conditional distribution of ZZ given X=xX=x under θk\theta_{k} to get

𝔼θk⁢(log⁡k⁢(Z|x;θ)|X=x)−𝔼θk⁢(log⁡k⁢(Z|x;θk)|X=x)\displaystyle\mathbb{E}_{\theta_{k}}\bigl{(}\log k(Z\mskip 1.0mu|\mskip 1.0mux% ;\theta)\!\mathrel{\big{|}}\!X=x\bigr{)}-\mathbb{E}_{\theta_{k}}\bigl{(}\log k% (Z\mskip 1.0mu|\mskip 1.0mux;\theta_{k})\!\mathrel{\big{|}}\!X=x\bigr{)}
=𝔼θk⁢(log⁡Y|X=x)≤log⁡𝔼θk⁢(Y|X=x)\displaystyle\qquad=\mathbb{E}_{\theta_{k}}\bigl{(}\log Y\!\mathrel{\big{|}}\!% X=x\bigr{)}\leq\log\mathbb{E}_{\theta_{k}}\bigl{(}Y\!\mathrel{\big{|}}\!X=x% \bigr{)}
=log⁢∑zk⁢(z|x;θ)k⁢(z|x;θk)⁢k⁢(z|x;θk)=log⁢∑zk⁢(z|x;θ)=log⁡1=0,\displaystyle\qquad=\log\sum_{z}\frac{k(z\mskip 1.0mu|\mskip 1.0mux;\theta)}{k% (z\mskip 1.0mu|\mskip 1.0mux;\theta_{k})}\,k(z\mskip 1.0mu|\mskip 1.0mux;% \theta_{k})=\log\sum_{z}k(z\mskip 1.0mu|\mskip 1.0mux;\theta)=\log 1=0,

since z↦k⁢(z|x;θ)z\mapsto k(z\mskip 1.0mu|\mskip 1.0mux;\theta) is a probability distribution over zz (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 θ=θk+1\theta=\theta_{k+1} and at θ=θk\theta=\theta_{k}, both with the same second argument θk\theta_{k}, and taking the difference we get

ℓ⁢(θk+1)−ℓ⁢(θk)=(Q⁢(θk+1|θk)−Q⁢(θk|θk))−(H⁢(θk+1|θk)−H⁢(θk|θk)).\ell(\theta_{k+1})-\ell(\theta_{k})=\bigl{(}Q(\theta_{k+1}\mskip 1.0mu|\mskip 1% .0mu\theta_{k})-Q(\theta_{k}\mskip 1.0mu|\mskip 1.0mu\theta_{k})\bigr{)}-\bigl% {(}H(\theta_{k+1}\mskip 1.0mu|\mskip 1.0mu\theta_{k})-H(\theta_{k}\mskip 1.0mu% |\mskip 1.0mu\theta_{k})\bigr{)}.

The first bracket is non-negative, since θk+1\theta_{k+1} is the maximiser of θ↦Q⁢(θ|θk)\theta\mapsto Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k}) 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 ℓ⁢(θk)\ell(\theta_{k}) converges whenever ℓ\ell 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 ℓ\ell.

Proposition 19.3.

Let Θ\Theta be open and ℓ\ell as well as θ↦Q⁢(θ|θ′)\theta\mapsto Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta^{\prime}) differentiable for all θ′∈Θ\theta^{\prime}\in\Theta. Then

ℓ′⁢(θ′)=∂∂θ⁢Q⁢(θ|θ′)|θ=θ′for all θ′∈Θ.\ell^{\prime}(\theta^{\prime})=\left.\frac{\partial}{\partial\theta}\,Q(\theta% \mskip 1.0mu|\mskip 1.0mu\theta^{\prime})\right|_{\theta=\theta^{\prime}}% \qquad\text{for all $\theta^{\prime}\in\Theta$.}

In particular, if θk+1=θk\theta_{k+1}=\theta_{k} for some kk, the point θk\theta_{k} is a root of the likelihood equation ℓ′⁢(θ)=0\ell^{\prime}(\theta)=0.

Proof.

From (19.1) we know that the function θ↦H⁢(θ|θ′)=Q⁢(θ|θ′)−ℓ⁢(θ)\theta\mapsto H(\theta\mskip 1.0mu|\mskip 1.0mu\theta^{\prime})=Q(\theta\mskip 1% .0mu|\mskip 1.0mu\theta^{\prime})-\ell(\theta) 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 θ′\theta^{\prime}. Thus, the derivative at this point must be zero. Taking derivatives of the decomposition at θ=θ′\theta=\theta^{\prime} gives the identity. If θk+1=θk\theta_{k+1}=\theta_{k}, then θk\theta_{k} is an interior maximiser of θ↦Q⁢(θ|θk)\theta\mapsto Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k}) and the right-hand side equals zero at θ′=θk\theta^{\prime}=\theta_{k}. Thus we have ℓ′⁢(θk)=0\ell^{\prime}(\theta_{k})=0. This completes the proof. ∎

For a vector parameter the same argument applies, but now using gradients instead of derivatives. Conversely, if the function θ↦Q⁢(θ|θ′)\theta\mapsto Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta^{\prime}) is strictly concave for all θ′\theta^{\prime}, then all roots of the likelihood equation are fixed points: The derivative of θ↦Q⁢(θ|θ∗)\theta\mapsto Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta^{*}) is zero at a root θ∗\theta^{*} 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.

Example 19.4.

Let Z1,…,ZnZ_{1},\dots,Z_{n} be i.i.d. with ℙ⁢(Zi=1)=π\mathbb{P}(Z_{i}=1)=\pi and ℙ⁢(Zi=2)=1−π\mathbb{P}(Z_{i}=2)=1-\pi and given Zi=jZ_{i}=j let Xi∼N⁢(μj,σ2)X_{i}\sim N(\mu_{j},\sigma^{2}), where σ2>0\sigma^{2}>0 is known and θ=(π,μ1,μ2)\theta=(\pi,\mu_{1},\mu_{2}) is unknown. Then the complete-data density is fc⁢(x,1;θ)=π⁢φσ⁢(x−μ1)f_{c}(x,1;\theta)=\pi\varphi_{\sigma}(x-\mu_{1}) and fc⁢(x,2;θ)=(1−π)⁢φσ⁢(x−μ2)f_{c}(x,2;\theta)=(1-\pi)\varphi_{\sigma}(x-\mu_{2}). Thus, the complete-data log-likelihood is

ℓc⁢(θ)=∑i=1n[𝟏{Zi=1}⁢(log⁡π+log⁡φσ⁢(xi−μ1))+𝟏{Zi=2}⁢(log⁡(1−π)+log⁡φσ⁢(xi−μ2))],\ell_{c}(\theta)=\sum_{i=1}^{n}\Bigl{[}\mathbf{1}_{\{Z_{i}=1\}}\bigl{(}\log\pi% +\log\varphi_{\sigma}(x_{i}-\mu_{1})\bigr{)}+\mathbf{1}_{\{Z_{i}=2\}}\bigl{(}% \log(1-\pi)+\log\varphi_{\sigma}(x_{i}-\mu_{2})\bigr{)}\Bigr{]},

which is linear in the indicators. For the E step, using Bayes’ rule with the current value θk=(πk,μ1,k,μ2,k)\theta_{k}=(\pi_{k},\mu_{1,k},\mu_{2,k}), we find

γi=ℙθk⁢(Zi=1|Xi=xi)=πk⁢φσ⁢(xi−μ1,k)πk⁢φσ⁢(xi−μ1,k)+(1−πk)⁢φσ⁢(xi−μ2,k),\gamma_{i}=\mathbb{P}_{\theta_{k}}(Z_{i}=1\mskip 1.0mu|\mskip 1.0muX_{i}=x_{i}% )=\frac{\pi_{k}\,\varphi_{\sigma}(x_{i}-\mu_{1,k})}{\pi_{k}\,\varphi_{\sigma}(% x_{i}-\mu_{1,k})+(1-\pi_{k})\,\varphi_{\sigma}(x_{i}-\mu_{2,k})},

This is called the responsibility of group 1 for the observation ii, and Q⁢(θ|θk)Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k}) is ℓc⁢(θ)\ell_{c}(\theta) with 𝟏{Zi=1}\mathbf{1}_{\{Z_{i}=1\}} replaced by γi\gamma_{i} and 𝟏{Zi=2}\mathbf{1}_{\{Z_{i}=2\}} replaced by 1−γi1-\gamma_{i}.

For the M step we maximise over θ=(π,μ1,μ2)\theta=(\pi,\mu_{1},\mu_{2}) with the γi\gamma_{i} fixed. Since log⁡φσ⁢(x−μ)=−(x−μ)2/(2⁢σ2)+const\log\varphi_{\sigma}(x-\mu)=-(x-\mu)^{2}/(2\sigma^{2})+\text{const}, the partial derivatives of QQ are

∂Q∂π\displaystyle\frac{\partial Q}{\partial\pi}
=∑iγiπ−∑i(1−γi)1−π,\displaystyle=\frac{\sum_{i}\gamma_{i}}{\pi}-\frac{\sum_{i}(1-\gamma_{i})}{1-% \pi},
∂Q∂μ1\displaystyle\frac{\partial Q}{\partial\mu_{1}}
=1σ2⁢∑i=1nγi⁢(xi−μ1),∂Q∂μ2=1σ2⁢∑i=1n(1−γi)⁢(xi−μ2),\displaystyle=\frac{1}{\sigma^{2}}\sum_{i=1}^{n}\gamma_{i}(x_{i}-\mu_{1}),% \qquad\frac{\partial Q}{\partial\mu_{2}}=\frac{1}{\sigma^{2}}\sum_{i=1}^{n}(1-% \gamma_{i})(x_{i}-\mu_{2}),

and setting these to zero gives the updates

equation (19.2) (19.2)
πk+1=1n⁢∑i=1nγi,μ1,k+1=∑iγi⁢xi∑iγi,μ2,k+1=∑i(1−γi)⁢xi∑i(1−γi).\pi_{k+1}=\frac{1}{n}\sum_{i=1}^{n}\gamma_{i},\qquad\mu_{1,k+1}=\frac{\sum_{i}% \gamma_{i}x_{i}}{\sum_{i}\gamma_{i}},\qquad\mu_{2,k+1}=\frac{\sum_{i}(1-\gamma% _{i})x_{i}}{\sum_{i}(1-\gamma_{i})}.

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 σ=1\sigma=1, together with the observations x=(0,1,5,6,7)x=(0,1,5,6,7) and initial value θ0=(1/2,2,4)\theta_{0}=(1/2,2,4). In this case we have π0=1/2\pi_{0}=1/2 and to cancel the weights we divide the numerator and denominator by φ1⁢(xi−2)\varphi_{1}(x_{i}-2) to get

γi=11+exp⁡(12⁢(xi−2)2−12⁢(xi−4)2)=11+e2⁢xi−6.\gamma_{i}=\frac{1}{1+\exp\bigl{(}\tfrac{1}{2}(x_{i}-2)^{2}-\tfrac{1}{2}(x_{i}% -4)^{2}\bigr{)}}=\frac{1}{1+e^{2x_{i}-6}}.

So, with four decimal digits we have

γ=(0.9975, 0.9820, 0.0180, 0.0025, 0.0003).\gamma=(0.9975,\,0.9820,\,0.0180,\,0.0025,\,0.0003).

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 ∑iγi=2.0003\sum_{i}\gamma_{i}=2.0003, ∑iγi⁢xi=1.0891\sum_{i}\gamma_{i}x_{i}=1.0891 and ∑i(1−γi)⁢xi=17.9109\sum_{i}(1-\gamma_{i})x_{i}=17.9109, we can use the update (19.2) to get

θ1=(2.00035,1.08912.0003,17.91092.9997)=(0.4001, 0.5445, 5.9709).\theta_{1}=\Bigl{(}\frac{2.0003}{5},\ \frac{1.0891}{2.0003},\ \frac{17.9109}{2% .9997}\Bigr{)}=(0.4001,\ 0.5445,\ 5.9709).

The log-likelihood of the observed data increases from ℓ⁢(θ0)=−17.52\ell(\theta_{0})=-17.52 to ℓ⁢(θ1)=−9.21\ell(\theta_{1})=-9.21, as required by theorem 19.2 (see exercise 19.3). For another iteration we find

θ2=(0.4000, 0.5001, 6.0000).\theta_{2}=(0.4000,\ 0.5001,\ 6.0000).

At this point the iteration no longer changes by more than four decimal digits: the responsibilities are so close to 0 or 11 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 (π,μ1,μ2)(\pi,\mu_{1},\mu_{2}) and (1−π,μ2,μ1)(1-\pi,\mu_{2},\mu_{1}) give the same density f⁢(x;θ)f(x;\theta), 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 (1/2,4,2)(1/2,4,2) instead of (1/2,2,4)(1/2,2,4) in example 19.4 converges to (0.6,6.0,0.5)(0.6,6.0,0.5) instead of (0.4,0.5,6.0)(0.4,0.5,6.0). 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 μ1<μ2\mu_{1}<\mu_{2}. 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 ℓ\ell 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 ℓ⁢(θk)\ell(\theta_{k}) 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.

Summary.
  • •
    ​

    In an incomplete-data model, the complete data (X,Z)(X,Z) has an easy log-likelihood ℓc\ell_{c}, but only XX is observed and the observed-data log-likelihood ℓ\ell has a sum inside the logarithm.

  • •
    ​

    EM iteratively computes the expectation Q⁢(θ|θk)=𝔼θk⁢(ℓc⁢(θ)|X)Q(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k})=\mathbb{E}_{\theta_{k}}\bigl{(}% \ell_{c}(\theta)\!\mathrel{\big{|}}\!X\bigr{)} and then maximises the expectation QQ over θ\theta.

  • •
    ​

    We have shown that ℓ⁢(θk+1)≥ℓ⁢(θk)\ell(\theta_{k+1})\geq\ell(\theta_{k}) for all kk. The proof uses ℓ=Q−H\ell=Q-H and Jensen’s inequality to show that the maximum of θ↦H⁢(θ|θk)\theta\mapsto H(\theta\mskip 1.0mu|\mskip 1.0mu\theta_{k}) is attained at θk\theta_{k}. 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 γi=ℙθk⁢(Zi=1|Xi=xi)\gamma_{i}=\mathbb{P}_{\theta_{k}}(Z_{i}=1\mskip 1.0mu|\mskip 1.0muX_{i}=x_{i}) 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.

Exercise 19.1.

Let XX be geometrically distributed with parameter p∈(0,1)p\in(0,1), i.e. f⁢(x;p)=(1−p)x−1⁢pf(x;p)=(1-p)^{x-1}p for x∈{1,2,…}x\in\{1,2,\dots\}, as in exercise 5.1.

  1. 1.
    ​

    Show that ℙp⁢(X≥m)=(1−p)m−1\mathbb{P}_{p}(X\geq m)=(1-p)^{m-1} for m∈{1,2,…}m\in\{1,2,\dots\} and use this result to show that ℙp⁢(X≥m+k|X≥m)=ℙp⁢(X≥k+1)\mathbb{P}_{p}(X\geq m+k\mskip 1.0mu|\mskip 1.0muX\geq m)=\mathbb{P}_{p}(X\geq k% +1) for all k≥0k\geq 0. Comment upon your result in the light of the memorylessness of the exponential distribution from exercise 5.6.

  2. 2.
    ​

    Show that

    𝔼p⁢(X|X≥m)=m−1+𝔼p⁢(X)=m−1+1pfor all m∈{1,2,…}.\mathbb{E}_{p}(X\mskip 1.0mu|\mskip 1.0muX\geq m)=m-1+\mathbb{E}_{p}(X)=m-1+% \frac{1}{p}\qquad\text{for all $m\in\{1,2,\dots\}$.}
Exercise 19.2.

Suppose f1f_{1} and f2f_{2} are two known, distinct densities, and that X1,…,XnX_{1},\dots,X_{n} are i.i.d. with density

f⁢(x;π)=π⁢f1⁢(x)+(1−π)⁢f2⁢(x),f(x;\pi)=\pi f_{1}(x)+(1-\pi)f_{2}(x),

where π∈(0,1)\pi\in(0,1) is the only unknown parameter. Let Zi∈{1,2}Z_{i}\in\{1,2\} be the component observation ii belongs to, as in example 19.4.

  1. 1.
    ​

    Write down the observed-data log-likelihood ℓ⁢(π)\ell(\pi) and the likelihood equation ℓ′⁢(π)=0\ell^{\prime}(\pi)=0.

  2. 2.
    ​

    Write down the complete-data log-likelihood and show that the E step determines the responsibilities γi⁢(πk)=πk⁢f1⁢(xi)/(πk⁢f1⁢(xi)+(1−πk)⁢f2⁢(xi))\gamma_{i}(\pi_{k})=\pi_{k}f_{1}(x_{i})/\bigl{(}\pi_{k}f_{1}(x_{i})+(1-\pi_{k}% )f_{2}(x_{i})\bigr{)} and the M step determines the update πk+1=1n⁢∑iγi⁢(πk)\pi_{k+1}=\frac{1}{n}\sum_{i}\gamma_{i}(\pi_{k}).

  3. 3.
    ​

    Show that γi⁢(π)−π=π⁢(1−π)⁢(f1⁢(xi)−f2⁢(xi))/f⁢(xi;π)\gamma_{i}(\pi)-\pi=\pi(1-\pi)\,\bigl{(}f_{1}(x_{i})-f_{2}(x_{i})\bigr{)}/f(x_% {i};\pi) and thus that 1n⁢∑iγi⁢(π)−π=π⁢(1−π)⁢ℓ′⁢(π)/n\frac{1}{n}\sum_{i}\gamma_{i}(\pi)-\pi=\pi(1-\pi)\,\ell^{\prime}(\pi)/n. Deduce that π∗∈(0,1)\pi^{*}\in(0,1) is a fixed point of the EM iteration if and only if it solves the likelihood equation, as in proposition 19.3.

Exercise 19.3.

For the data, starting value and first iterate of the numerical illustration in example 19.4, compute the observed-data log-likelihood ℓ⁢(θ)=∑i=15log⁡(π⁢φ1⁢(xi−μ1)+(1−π)⁢φ1⁢(xi−μ2))\ell(\theta)=\sum_{i=1}^{5}\log\bigl{(}\pi\varphi_{1}(x_{i}-\mu_{1})+(1-\pi)% \varphi_{1}(x_{i}-\mu_{2})\bigr{)} for θ0=(1/2,2,4)\theta_{0}=(1/2,2,4) and θ1=(0.4001,0.5445,5.9709)\theta_{1}=(0.4001,0.5445,5.9709). Show that the likelihood has increased. Which of the five observations contributes most to the increase in likelihood? Why?

Exercise 19.4.

Consider the two-component normal mixture from example 19.4, but with known weight π∈(0,1)\pi\in(0,1) and known variance σ2\sigma^{2}. The only unknown quantities are the means θ=(μ1,μ2)\theta=(\mu_{1},\mu_{2}).

  1. 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 π\pi.

  2. 2.
    ​

    Compute the derivative of the observed-data log-likelihood and show that

    ∂ℓ∂μ1⁢(θ)=1σ2⁢∑i=1nγi⁢(θ)⁢(xi−μ1),\frac{\partial\ell}{\partial\mu_{1}}(\theta)=\frac{1}{\sigma^{2}}\sum_{i=1}^{n% }\gamma_{i}(\theta)\,(x_{i}-\mu_{1}),

    where γi⁢(θ)\gamma_{i}(\theta) is the responsibility at θ\theta. Deduce that the likelihood equations coincide with the fixed-point equations of the EM iteration.

  3. 3.
    ​

    What are the updates in the limit π→1\pi\to 1? Comment upon your result in the context of example 5.4.