Tutorials › Pattern-Mixture and Selection Models › EM Estimation for Shared-Random-Effects Models

Shared-Parameter Models · Tutorial 451 of 499

EM Estimation for Shared-Random-Effects Models

Learn how latent random effects drive the EM expectation step and how their posterior moments support outcome, dropout, and variance parameter updates.

Advanced 12 min read

What You'll Learn

  • Specify the complete-data likelihood for a shared-random-effects model.
  • Compute posterior expectations of random effects and their squares in an E-step.
  • Update regression coefficients and residual variance for Gaussian outcomes.
  • Form the dropout-model update as an expected complete-data log-likelihood.
  • Update random-effects covariance using posterior second moments.
  • Check numerical integration and distinguish EM from direct likelihood maximization.

Why use EM for shared-random-effects models?

In a shared-parameter model, a latent subject-specific effect helps describe both the outcome history and the dropout process. The observed-data likelihood averages over that unobserved effect, which can make direct maximization difficult. The expectation-maximization (EM) algorithm instead alternates between calculating the posterior distribution of the latent effects under the current parameters and maximizing an expected complete-data log-likelihood.

The algorithm does not make dropout ignorable. The dropout contribution remains in the likelihood and therefore in the posterior distribution calculated at each E-step. Nor does EM create information about parameters that the observed data cannot identify: the identifiability conditions discussed in the earlier material on shared effects still apply.

Model and complete-data likelihood

Consider \(n\) independent subjects. Subject \(i\) has a \(q\)-dimensional random effect \(b_i\), with \(b_i\sim N_q(0,D)\). At observed outcome times \(j\in\mathcal O_i\), suppose \(Y_{ij}=x_{ij}^{T}\beta+z_{ij}^{T}b_i+\varepsilon_{ij}\), where the errors are independent \(N(0,\sigma^2)\) conditional on \(b_i\). For a discrete-time dropout process, let \(d_{it}=1\) indicate dropout in interval \(t\), and let \(r_{it}=1\) indicate the subject is at risk at the start of that interval. Use \(\operatorname{logit}(h_{it})=w_{it}^{T}\gamma+a_{it}^{T}b_i\), where \(h_{it}=P(d_{it}=1\mid r_{it}=1,b_i)\). The dropout contribution is included only for intervals in which \(r_{it}=1\).

Definition: The complete data for this likelihood consist of the observed outcomes and dropout history together with the latent random effects \(b_1,\ldots,b_n\). The complete-data likelihood includes the outcome density, the dropout-history likelihood conditional on the random effects, and the random-effects density. The parameter vector is \(\theta=(\beta,\gamma,\sigma^2,D)\).

For example, subject \(i\)'s complete-data log-likelihood, omitting constants that do not depend on \(\theta\), is

$$ \ell_{c,i}(\theta)= -\frac{m_i}{2}\log(\sigma^2) -\frac{1}{2\sigma^2}\sum_{j\in\mathcal O_i} (Y_{ij}-x_{ij}^{T}\beta-z_{ij}^{T}b_i)^2 +\sum_{t:r_{it}=1}\{d_{it}\eta_{it}-\log(1+\exp(\eta_{it}))\} -\frac{1}{2}\log|D|-\frac{1}{2}b_i^{T}D^{-1}b_i , \qquad \eta_{it}=w_{it}^{T}\gamma+a_{it}^{T}b_i , $$

Here \(m_i\) is the number of observed outcomes for subject \(i\). The term \(-q\log(2\pi)/2\), as well as the normal-outcome constant, is omitted. A different outcome or dropout model changes the corresponding likelihood terms, but not the EM principle.

The E-step and M-step

At iteration \(k\), the E-step uses the current estimate \(\theta^{(k)}\) to form each subject's posterior distribution of \(b_i\), conditional on that subject's observed outcomes and dropout history. In this model its density is proportional to the product of the observed-outcome density, the dropout-history likelihood, and the \(N_q(0,D^{(k)})\) density. The E-step computes expectations under that posterior; common required quantities include \(E[b_i\mid\mathrm{obs}_i]\), \(E[b_ib_i^{T}\mid\mathrm{obs}_i]\), and expectations of the dropout log-likelihood terms.

In the M-step, maximize \(Q(\theta\mid\theta^{(k)})=\sum_i E_{\theta^{(k)}}[\ell_{c,i}(\theta)\mid\mathrm{obs}_i]\). For the Gaussian outcome component, the regression update has a closed form when the design matrices are fixed. The residual variance update uses the posterior expectation of the squared residual, not just the squared residual evaluated at the posterior mean. The covariance update uses posterior second moments. For a logistic dropout model, the expected log-likelihood generally has no closed-form maximizing coefficient, so numerical maximization is used.

1
Evaluate posterior quantities.
For each subject, integrate over \(b_i\) using the current parameter values to obtain the posterior expectations needed by the complete-data terms.
2
Update outcome parameters.
Maximize the expected Gaussian outcome log-likelihood for \(\beta\) and \(\sigma^2\).
3
Update dropout and random-effects parameters.
Maximize the expected dropout log-likelihood for \(\gamma\), and update \(D\) from the expected random-effects cross-products.
4
Repeat and check.
Recalculate posterior expectations at the new parameter values, then check the observed-data likelihood and numerical integration accuracy.

Why the EM step increases likelihood

Let \(Z\) denote all the latent random effects, and let \(p_\theta(y_{\mathrm{obs}},Z)\) be the joint density of the observed data and latent effects. Set \(q(Z)=p_{\theta^{(k)}}(Z\mid y_{\mathrm{obs}})\). For any candidate \(\theta\), writing the observed likelihood as an integral against \(q\) and applying Jensen's inequality gives

$$ \ell(\theta) =\log\int q(Z)\frac{p_\theta(y_{\mathrm{obs}},Z)}{q(Z)}\,dZ \geq E_q[\log p_\theta(y_{\mathrm{obs}},Z)]-E_q[\log q(Z)]. $$

The second expectation on the right does not depend on the candidate \(\theta\). The first is \(Q(\theta\mid\theta^{(k)})\). At \(\theta=\theta^{(k)}\), the inequality is an equality because \(q\) is that parameter value's posterior. Consequently, an exact M-step that does not decrease \(Q\) cannot decrease the observed-data log-likelihood. With approximate integration or an incomplete numerical maximization, this guarantee may not hold exactly, so the observed likelihood should be monitored.

Worked calculations

Worked Example: Posterior Weights at Two Integration Points

Hypothetical calculation. Suppose a one-dimensional E-step is approximated at two points \(b=0\) and \(b=2\). Assume the conditional observed-data likelihood is equal at these points, so the unnormalized posterior weights are proportional to the standard normal prior densities there. The standard normal density is \(\phi(b)=(2\pi)^{-1/2}\exp(-b^2/2)\).

The density values are \(\phi(0)=0.398942\) and \(\phi(2)=0.053991\). Normalizing gives \(w_0=0.398942/(0.398942+0.053991)=0.8808\) and \(w_2=0.053991/(0.398942+0.053991)=0.1192\). They sum to 1, as required.

The posterior mean and second moment under this two-point approximation are \(E[b\mid\mathrm{obs}]\approx 0(0.8808)+2(0.1192)=0.2384\), and \(E[b^2\mid\mathrm{obs}]\approx 0^2(0.8808)+2^2(0.1192)=0.4768\). These are integration-point approximations, not exact posterior moments. In particular, \(E[b^2\mid\mathrm{obs}]\) is not \(\{E[b\mid\mathrm{obs}]\}^2\).

Worked Example: Gaussian Outcome and Residual-Variance Updates

Hypothetical M-step. Consider two subjects with one observed outcome each, under \(Y_i=\beta+b_i+\varepsilon_i\). Suppose the E-step gives \(E[b_1\mid\mathrm{obs}]=0.20\), \(E[b_1^2\mid\mathrm{obs}]=0.50\), \(E[b_2\mid\mathrm{obs}]=-0.10\), and \(E[b_2^2\mid\mathrm{obs}]=0.40\). Let the observed values be \(Y_1=2\) and \(Y_2=4\).

The intercept update sets the average expected residual to zero: \(\beta^{\mathrm{new}}=\{(2-0.20)+(4-(-0.10))\}/2=5.90/2=2.950\). For the variance, use \(E[(Y_i-\beta-b_i)^2]=(Y_i-\beta)^2-2(Y_i-\beta)E[b_i]+E[b_i^2]\). For subject 1 this is \((2-2.95)^2-2(2-2.95)(0.20)+0.50=0.9025+0.3800+0.5000=1.7825\). For subject 2 it is \((4-2.95)^2-2(4-2.95)(-0.10)+0.40=1.1025+0.2100+0.4000=1.7125\).

There are two observed outcomes, so \((\sigma^2)^{\mathrm{new}}=(1.7825+1.7125)/2=1.7475\), in squared outcome units. The example illustrates why replacing \(b_i\) by its posterior mean in each residual would omit posterior uncertainty and generally give a different variance update.

Worked Example: A Dropout-Intercept Update

Hypothetical numerical M-step. Suppose two subjects are at risk for one interval, one drops out (\(d_1=1\)) and one does not (\(d_2=0\)). For illustration, each subject has the same two-point E-step posterior, \(P(b=1\mid\mathrm{obs})=0.8808\) and \(P(b=-1\mid\mathrm{obs})=0.1192\). Consider the dropout logit \(\eta=\gamma_0+0.5b\), with slope \(0.5\) held fixed in this intercept-only update.

The expected complete-data score for \(\gamma_0\) is \(\sum_i E[d_i-\operatorname{expit}(\gamma_0+0.5b_i)\mid\mathrm{obs}_i]\). At \(\gamma_0=0\), the posterior-averaged dropout probability for either subject is \(0.8808\operatorname{expit}(0.5)+0.1192\operatorname{expit}(-0.5)\) \(=0.8808(0.62246)+0.1192(0.37754)\approx0.5933\). Thus the score is \(1-2(0.5933)=-0.1866\). The expected second derivative is \(-2\{0.8808(0.62246)(1-0.62246)+0.1192(0.37754)(1-0.37754)\}\approx-0.4700\).

A Newton step is \(\gamma_0^{\mathrm{new}}=0-(-0.1866)/(-0.4700)\approx-0.397\). This is one numerical step, not a claim that one step maximizes the expected log-likelihood. Continuing the one-dimensional maximization gives a root near \(-0.387\), where the two expected dropout probabilities sum to approximately 1, matching the one event among two at-risk records. In a full model, the shared-effect slope and other dropout coefficients are generally updated jointly by numerical maximization.

General M-step formulas and practical checks

For the Gaussian outcome model, stack the observed outcomes for subject \(i\) into \(Y_i\), and let \(X_i\) and \(Z_i\) be the corresponding fixed- and random-effect design matrices. If \(\sum_i X_i^{T}X_i\) is invertible, the update is

$$ \beta^{\mathrm{new}}= \left(\sum_iX_i^{T}X_i\right)^{-1} \sum_iX_i^{T}\{Y_i-Z_iE[b_i\mid\mathrm{obs}_i]\}, \qquad (\sigma^2)^{\mathrm{new}}= \frac{\sum_i E[\|Y_i-X_i\beta^{\mathrm{new}}-Z_ib_i\|^2\mid\mathrm{obs}_i]} {\sum_i m_i}. $$

The denominator in the variance update is the number of observed outcome measurements under this likelihood, not the number of subjects. If \(D\) is unrestricted and the random-effects mean is fixed at zero, its update is

$$ D^{\mathrm{new}}=\frac{1}{n}\sum_{i=1}^{n}E[b_ib_i^{T}\mid\mathrm{obs}_i]. $$

This update uses second moments, including uncertainty about the latent effects. Constraints such as a diagonal \(D\) require the corresponding constrained maximization rather than blindly retaining all estimated off-diagonal entries.

For the dropout coefficients, the M-step maximizes \(\sum_i E[\sum_{t:r_{it}=1}\{d_{it}\eta_{it}-\log(1+\exp(\eta_{it}))\}\mid\mathrm{obs}_i]\). The expectation is over each subject's posterior distribution of \(b_i\). It can be evaluated by quadrature or another integration method, then maximized numerically. The dropout update is not an ordinary logistic regression on estimated random effects: treating posterior means as known covariates discards posterior uncertainty and does not, in general, maximize this expected likelihood.

A practical E-step often needs numerical integration because the posterior combines the random-effects density with outcome and dropout terms. The earlier material on maximum likelihood estimation with adaptive quadrature develops a direct-likelihood integration approach; in EM, integration instead supplies posterior expectations for \(Q\). Check that increasing the integration accuracy does not materially change those expectations or the resulting updates. Also verify that probabilities are valid, covariance estimates are positive semidefinite, and the observed-data log-likelihood does not fall materially after an iteration. A substantial decrease can signal inaccurate integration, a failed M-step optimization, or an implementation error.

Comparison, limitations, and common mistakes

ApproachWhat is optimized or calculatedPractical implication
EMExpected complete-data log-likelihood, using posterior latent-effect expectationsOften yields simple outcome and covariance updates; dropout updates may need numerical optimization.
Direct maximum likelihood with adaptive quadratureObserved-data likelihood, integrating out random effects at each parameter valueProvides direct likelihood optimization, but requires repeated integration while optimizing.

EM is useful when complete-data terms have convenient updates and posterior moments can be calculated reliably. Its limitations include the need for repeated E-steps, potential sensitivity to starting values in a non-concave problem, and slow progress in some regions of the parameter space. An increase in likelihood does not establish that the model fits well, that parameters are identifiable, or that the shared-effects assumptions are scientifically appropriate. Those questions require separate assessment.

Common mistake: “I can update the variance using \((Y_i-X_i^T\beta-Z_i^TE[b_i\mid\mathrm{obs}_i])^2\), because the posterior mean is the best estimate of \(b_i\).” This replaces a latent random effect by a point estimate. The correct EM update averages the squared residual over its full posterior distribution: \(E[(Y_i-X_i^T\beta-Z_i^Tb_i)^2\mid\mathrm{obs}_i]\). The difference includes posterior variance and can materially affect \(\sigma^2\) and \(D\).

Key takeaway: The E-step must use the posterior of the shared random effects given both observed outcomes and dropout history. The M-step then uses the resulting first and second moments for outcome and variance updates, and maximizes an expected dropout likelihood for dropout parameters.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. Which observed information enters the posterior distribution of \(b_i\) in the E-step of a shared-parameter model?
  2. Why is \(E[b_ib_i^T\mid\mathrm{obs}_i]\) generally not equal to \(E[b_i\mid\mathrm{obs}_i]E[b_i\mid\mathrm{obs}_i]^T\)?
  3. For \(n\) subjects with unequal numbers \(m_i\) of observed outcomes, what is the denominator in the Gaussian residual-variance update?
  4. Does the logistic dropout M-step generally have a closed-form update for all its coefficients? Explain.
  5. Name one check that can reveal an inaccurate numerical E-step or failed M-step.

Solutions. (1) Both the subject's observed outcome contributions and dropout-history contributions, together with the random-effects density, enter the posterior. (2) The second moment includes posterior covariance as well as the outer product of the posterior mean; equality holds only if posterior uncertainty is zero. (3) The denominator is \(\sum_i m_i\), the total number of observed outcome measurements for this likelihood. (4) No. The expected logistic log-likelihood usually requires numerical maximization because it averages nonlinear terms over the random-effects posterior. (5) Check that the observed-data log-likelihood does not materially decrease after the update; also check stability of posterior expectations as integration accuracy increases.

Clinical Biostats