Tutorials › Nonlinear Mixed-Effects Models (NLME) › A Worked EM Update for a Gaussian Random-Intercept Model

The EM and SAEM Algorithms · Tutorial 203 of 797

A Worked EM Update for a Gaussian Random-Intercept Model

Calculate the conditional moments and complete one maximum-likelihood EM update for a Gaussian random-intercept model.

Advanced 11 min read

What You'll Learn

  • State the Gaussian random-intercept model and its independence assumptions.
  • Derive the conditional distribution of each random intercept given its subject’s observations.
  • Calculate conditional first and second moments for the E-step.
  • Update the fixed intercept, random-intercept variance, and residual variance in the M-step.
  • Check the arithmetic and recognize when the closed-form update’s assumptions do not hold.

Why Work Through a Complete EM Iteration?

In a nonlinear mixed-effects model, the individual random effects are unobserved. The EM algorithm handles this by taking conditional expectations of complete-data quantities, then maximizing the resulting expected complete-data log-likelihood. A Gaussian random-intercept model is a useful setting in which to see each calculation explicitly: the conditional distribution and the M-step updates both have closed forms.

The calculations below use maximum likelihood, not an unbiased variance estimator. The E-step expectations are taken under the current parameter values; the M-step then updates the population parameters using those expectations. Keeping those two roles distinct is essential to getting a correct iteration.

Model and Assumptions

Definition: For subjects \(i=1,\ldots,m\), suppose subject \(i\) has \(n_i\) observations, and \(N=\sum_{i=1}^m n_i\). The Gaussian random-intercept model is $$ y_{ij}=\beta+b_i+\epsilon_{ij}, \qquad j=1,\ldots,n_i, $$ where \(b_i\sim N(0,\tau^2)\) and \(\epsilon_{ij}\sim N(0,\sigma^2)\). The random effects are mutually independent, the residuals are mutually independent, and all random effects are independent of all residuals. The unknown parameters are \(\theta=(\beta,\tau^2,\sigma^2)\), with \(\tau^2>0\) and \(\sigma^2>0\).

The fixed intercept is \(\beta\), measured in the units of \(y\); the random intercept \(b_i\) is a subject-specific deviation in the same units. The zero mean of \(b_i\) defines the population intercept. The assumptions include a common residual variance and a common random-intercept variance across subjects. Conditional on the random effects, the observations are independent Gaussian measurements.

At iteration \(t\), write the current parameter values as \(\theta^{(t)}=(\beta^{(t)},\tau^{2(t)},\sigma^{2(t)})\). The E-step conditions on the observed responses and these current values. The formulas below rely on the stated Gaussian model; they are not the corresponding conditional moments for a general nonlinear mixed model.

Conditional Random-Effect Moments

For subject \(i\), let \(r_{ij}^{(t)}=y_{ij}-\beta^{(t)}\). The likelihood contribution involving \(b_i\), multiplied by its Gaussian prior density, is proportional to $$ \exp\left\{-\frac{1}{2}\left[\frac{b_i^2}{\tau^{2(t)}}+ \frac{\sum_{j=1}^{n_i}(r_{ij}^{(t)}-b_i)^2}{\sigma^{2(t)}}\right]\right\}. $$ Collecting the terms quadratic and linear in \(b_i\) gives conditional precision \(1/\tau^{2(t)}+n_i/\sigma^{2(t)}\). Completing the square therefore gives

$$ b_i\mid \mathbf y_i,\theta^{(t)}\sim N\left(m_i^{(t)},v_i^{(t)}\right),\qquad v_i^{(t)}=\left(\frac{1}{\tau^{2(t)}}+\frac{n_i}{\sigma^{2(t)}}\right)^{-1},\qquad m_i^{(t)}=v_i^{(t)}\frac{\sum_{j=1}^{n_i}(y_{ij}-\beta^{(t)})}{\sigma^{2(t)}}. $$

Here \(\mathbf y_i\) denotes all observations from subject \(i\). The conditional second moment is not just the square of the conditional mean:

$$ E[b_i^2\mid \mathbf y_i,\theta^{(t)}]=v_i^{(t)}+\left(m_i^{(t)}\right)^2. $$

The variance term matters because the random effect remains uncertain after observing the data. In the M-step, the random-intercept variance uses the average of these conditional second moments, not the average of the squared conditional means.

Worked Example: A Conditional Mean and Second Moment

Suppose a hypothetical subject has two observations, \(y_{i1}=11\) and \(y_{i2}=12\), with current values \(\beta^{(t)}=10\), \(\tau^{2(t)}=4\), and \(\sigma^{2(t)}=1\). The residuals relative to the current fixed intercept are 1 and 2.

The conditional variance is \(v_i^{(t)}=(1/4+2/1)^{-1}=4/9\). The conditional mean is \(m_i^{(t)}=(4/9)(1+2)/1=4/3\). Thus the conditional second moment is \(4/9+(4/3)^2=4/9+16/9=20/9\), or approximately \(2.222\), in squared response units.

The second moment exceeds the squared mean \(16/9\) by the conditional variance \(4/9\), as it must. Using \(16/9\) alone would discard uncertainty about this subject’s random intercept.

Deriving the M-Step Updates

The complete-data log-likelihood, up to terms not involving the parameters, is

$$ \ell_c(\theta)=-\frac{m}{2}\log(\tau^2)-\frac{1}{2\tau^2}\sum_{i=1}^m b_i^2 -\frac{N}{2}\log(\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^m\sum_{j=1}^{n_i}(y_{ij}-\beta-b_i)^2. $$

In the M-step, take its conditional expectation using the E-step distribution, then maximize with respect to \(\beta,\tau^2,\sigma^2\). The terms for \(\beta\) give a weighted sum of expected squared residuals. Differentiating that sum with respect to \(\beta\) sets the sum of expected residuals to zero:

$$ \sum_{i=1}^m\sum_{j=1}^{n_i}\left(y_{ij}-\beta-E[b_i\mid\mathbf y_i,\theta^{(t)}]\right)=0. $$

For the variance terms, maximizing \(-k\log(q)/2-S/(2q)\) over \(q>0\) gives \(q=S/k\): its derivative is \(-k/(2q)+S/(2q^2)\), which vanishes at \(q=S/k\), and the expression is maximized there. Applying this result to each variance term yields the updates:

$$ \beta^{(t+1)}=\frac{1}{N}\sum_{i=1}^m\sum_{j=1}^{n_i}\left(y_{ij}-m_i^{(t)}\right), $$
$$ \tau^{2(t+1)}=\frac{1}{m}\sum_{i=1}^m\left[v_i^{(t)}+\left(m_i^{(t)}\right)^2\right], $$
$$ \sigma^{2(t+1)}=\frac{1}{N}\sum_{i=1}^m\sum_{j=1}^{n_i} \left[\left(y_{ij}-\beta^{(t+1)}-m_i^{(t)}\right)^2+v_i^{(t)}\right]. $$

The residual update follows from \(E[(y_{ij}-\beta-b_i)^2\mid\mathbf y_i,\theta^{(t)}]=(y_{ij}-\beta-m_i^{(t)})^2+v_i^{(t)}\). The old conditional moments appear throughout these updates; only the fixed intercept inside the residual calculation is the newly updated value. The denominators are \(m\) for the random-effect variance and \(N\) for the residual variance because these are maximum-likelihood updates.

Worked Example: One Complete EM Iteration

Consider hypothetical observations from three subjects: subject 1 has \((8,10)\), subject 2 has \((11,13)\), and subject 3 has \((9,12)\). Start at \(\beta^{(t)}=10\), \(\tau^{2(t)}=4\), and \(\sigma^{2(t)}=1\). There are \(m=3\) subjects and \(N=6\) observations. Each subject has two observations, so each has \(v_i^{(t)}=(1/4+2)^{-1}=4/9\).

The sums of observations minus the current fixed intercept, by subject, are \(-2,4,1\). Multiplying each by \(v_i^{(t)}/\sigma^{2(t)}=4/9\) gives conditional means \(-8/9,16/9,4/9\). The corresponding second moments are \(4/9+64/81=100/81\), \(4/9+256/81=292/81\), and \(4/9+16/81=52/81\). In particular, for subject 2 the second moment is approximately \(3.605\), not \(1.235\).

The total of the six observations is 63, and the sum of the conditional means across subjects is \((-8+16+4)/9=4/3\). Each mean is used twice in the fixed-intercept update, so \(\beta^{(t+1)}=(63-2(4/3))/6=181/18\approx10.06\).

For the random-intercept variance, the second moments sum to \((100+292+52)/81=444/81\). Therefore, \(\tau^{2(t+1)}=(444/81)/3=148/81\approx1.827\), in squared response units.

For the residual update, the fitted values \(\beta^{(t+1)}+m_i^{(t)}\) are \(55/6\), \(71/6\), and \(10.5\) for the three subjects. The within-subject squared residual sums around these fitted values are respectively \(74/36=37/18\), \(74/36=37/18\), and \(9/2\). Together they sum to \(155/18\). The conditional-variance contributions sum to \(6(4/9)=8/3\). Hence \(\sigma^{2(t+1)}=(155/18+8/3)/6=(203/18)/6=203/108\approx1.880\), in squared response units.

Thus one complete update gives \(\beta^{(t+1)}\approx10.06\), \(\tau^{2(t+1)}\approx1.827\), and \(\sigma^{2(t+1)}\approx1.880\). These are the next parameter values, not standard errors or confidence intervals.

Worked Example: Conditional Shrinkage With One Observation

Suppose another hypothetical subject has one observation \(y_{i1}=12\), with current \(\beta^{(t)}=10\), \(\tau^{2(t)}=4\), and \(\sigma^{2(t)}=1\). The residual relative to the current intercept is 2. Since \(n_i=1\), \(v_i^{(t)}=(1/4+1)^{-1}=4/5\), and \(m_i^{(t)}=(4/5)(2)=8/5=1.6\).

The second moment is \(4/5+(8/5)^2=20/25+64/25=84/25=3.36\). The conditional mean \(1.6\) is smaller than the observed residual 2: the prior distribution centered at zero shrinks the estimate toward zero. With fewer observations than in the previous example, the conditional variance is also larger, \(0.8\) rather than \(4/9\). This calculation is conditional on the stated Gaussian model and current parameter values.

Checks, Diagnostics, and Limitations

Before interpreting an iteration, check that the conditional variances are positive, that \(E[b_i^2\mid\mathbf y_i,\theta^{(t)}]\geq (m_i^{(t)})^2\), and that the variance updates use the correct denominators. Also check units: \(\beta\) and \(m_i^{(t)}\) have response units, while \(\tau^2\), \(\sigma^2\), and the conditional second moments have squared response units.

A negative updated variance, or a second moment smaller than the squared mean, signals an arithmetic or implementation error under this model. A variance approaching zero is different: it may be a boundary estimate or a sign that the data provide little information to distinguish variation at that level. It warrants examination of the fit and assumptions, rather than silently replacing the estimate with an arbitrary positive number.

The closed forms depend on the linear Gaussian random-intercept structure. With a nonlinear observation model, the conditional distribution of random effects is generally not Gaussian, and these exact conditional moments and closed-form updates need not apply. Direct marginal-likelihood optimization is an alternative way to estimate parameters, but it requires evaluating or approximating the integral over random effects. The earlier material on the EM and SAEM algorithms explains why exact EM can be difficult in nonlinear mixed models; the present calculations are an exact, tractable special case.

A common mistake is to update \(\tau^2\) using only \(\sum_i(m_i^{(t)})^2/m\). That treats each conditional mean as if it were the known random effect. The correct update adds the uncertainty for every subject: \(\tau^{2(t+1)}=\sum_i[(m_i^{(t)})^2+v_i^{(t)}]/m\). Another mistake is to calculate the conditional moments using the newly updated parameters partway through the E-step. In an EM iteration, all conditional moments for that iteration use \(\theta^{(t)}\); the resulting expectations are then used in the M-step.

Under the stated model and an exact E-step and M-step, the observed-data likelihood does not decrease from one EM iteration to the next. That property does not guarantee rapid convergence or prove that the fitted model is appropriate. In practice, inspect the likelihood trace and parameter changes, and assess whether the assumptions of a common Gaussian random-intercept distribution and independent Gaussian residuals are plausible for the application.

Check Your Understanding

Try each question, then compare your work with the solutions.

  1. For \(n_i=3\), \(\tau^{2(t)}=2\), and \(\sigma^{2(t)}=6\), calculate \(v_i^{(t)}\).
  2. If a subject has \(m_i^{(t)}=0.5\) and \(v_i^{(t)}=0.25\), calculate the conditional second moment.
  3. Why does the random-intercept variance update divide by \(m\), whereas the residual variance update divides by \(N\)?
  4. For a subject with one observation, suppose \(y_{i1}-\beta^{(t)}=1\), \(\tau^{2(t)}=1\), and \(\sigma^{2(t)}=1\). Calculate the conditional mean and variance.

Solutions. (1) \(v_i^{(t)}=(1/2+3/6)^{-1}=1\), in squared response units. (2) \(E[b_i^2\mid\mathbf y_i,\theta^{(t)}]=0.25+0.5^2=0.50\), in squared response units. (3) There is one random effect per subject, so its complete-data Gaussian variance term has \(m\) contributions; there are \(N\) residuals, so the residual variance term has \(N\) contributions. (4) \(v_i^{(t)}=(1+1)^{-1}=0.5\), and \(m_i^{(t)}=0.5(1)=0.5\). The mean is in response units and the variance is in squared response units.