Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › M-Step Updates for Random-Effects Covariance

Maximum Likelihood and EM Estimation · Tutorial 272 of 697

M-Step Updates for Random-Effects Covariance

Learn to update an unstructured or constrained random-effects covariance using posterior second moments, while keeping posterior variance distinct from squared posterior means.

Advanced 10 min read

What You'll Learn

  • Derive the covariance M-step from the complete-data random-effects density.
  • Express each posterior second moment as posterior covariance plus the outer product of the posterior mean.
  • Calculate scalar and multivariate covariance updates from hypothetical posterior summaries.
  • Apply diagonal covariance constraints and distinguish them from an unstructured update.
  • Diagnose omitted uncertainty, non-positive-definite estimates, and numerical problems in posterior moments.

Why Posterior Uncertainty Belongs in the Covariance Update

In an EM algorithm for a joint model, the subject-specific random effects are latent. The E-step therefore supplies their posterior distributions, not their true values. The covariance M-step must average the random-effects contribution to the complete-data log likelihood over those posterior distributions. Squaring posterior means alone treats uncertain latent effects as if they were known, and generally understates the covariance.

This tutorial derives the update for a shared, mean-zero random-effects distribution. The longitudinal measurements and the time-to-event outcome both inform the posterior distribution of a subject’s random effects. For this M-step, their information enters through the posterior moments from the E-step; the update itself concerns only the random-effects covariance.

Definition: For subject \(i=1,\ldots,n\), let \(b_i\) be a \(q\)-dimensional random-effects vector with prior distribution \(b_i\sim N(0,D)\), where \(D\) is a common \(q\times q\) covariance matrix. Let \(O_i\) denote all observed data for that subject, including longitudinal and event-time information. At the current parameter values, define the posterior mean \(m_i=E(b_i\mid O_i)\) and posterior covariance \(V_i=\operatorname{Var}(b_i\mid O_i)\). The posterior second-moment matrix is \(S_i=E(b_i b_i^\mathsf{T}\mid O_i)\).

The notation \(D\) refers to the population covariance of the random effects, whereas \(V_i\) describes the remaining posterior uncertainty about subject \(i\)’s random effects after observing that subject’s data. These matrices are not interchangeable: \(V_i\) varies by subject and is conditional on observed data; \(D\) is the shared model parameter being updated.

Deriving the Unstructured Covariance Update

Assume subjects are independent, their random effects share the same mean-zero normal distribution, and \(D\) is positive definite. Assume also that the E-step posterior second moments exist and are computed under the current parameter values. Other model parameters are held at their current values while maximizing the part of the EM auxiliary function that depends on \(D\).

The random-effects density for one subject contributes a term involving \(\log|D|\) and \(b_i^\mathsf{T}D^{-1}b_i\) to the complete-data log likelihood. Summing over subjects and taking the conditional expectation given the observed data gives the part of the auxiliary function that depends on \(D\):

$$ Q_D(D)=-\frac{n}{2}\log|D|-\frac{1}{2}\sum_{i=1}^n \operatorname{tr}\!\left(D^{-1}S_i\right)+C, $$

where \(C\) does not depend on \(D\). The trace expression follows from the identity \(b_i^\mathsf{T}D^{-1}b_i=\operatorname{tr}(D^{-1}b_i b_i^\mathsf{T})\), followed by taking the posterior expectation. Write \(A=\sum_{i=1}^n S_i\). Differentiating with respect to a symmetric positive-definite \(D\), the differential of this objective is

$$ dQ_D = -\frac{n}{2}\operatorname{tr}(D^{-1}dD) +\frac{1}{2}\operatorname{tr}(D^{-1} A D^{-1}dD). $$

At an interior maximum, the coefficient of \(dD\) is zero. Multiplying the resulting matrix equation on the left and right by \(D\) yields \(A=nD\). Thus the unstructured update is the average posterior second-moment matrix.

$$ D^{\text{new}} = \frac{1}{n}\sum_{i=1}^n E(b_i b_i^\mathsf{T}\mid O_i) = \frac{1}{n}\sum_{i=1}^n \left(V_i+m_i m_i^\mathsf{T}\right). $$

The last equality uses the standard second-moment decomposition: a random vector’s second moment equals its covariance plus the outer product of its mean with itself. In this update, the posterior moments are evaluated at the current parameters, and \(D^{\text{new}}\) is the value that maximizes this part of the auxiliary function when \(D\) is unrestricted.

Worked Example: Updating a Random-Intercept Variance

Suppose three hypothetical subjects have scalar random intercepts, measured in score units. At the current E-step, their posterior means are \(1.0\), \(-1.0\), and \(0.5\) score units, and their posterior variances are \(0.25\), \(0.36\), and \(0.16\) score-units squared. Assume the shared random-intercept mean is zero and the variance is unrestricted.

For each subject, the posterior second moment is the posterior variance plus the squared posterior mean:

$$ \begin{aligned} S_1 &= 0.25+(1.0)^2=1.25,\\ S_2 &= 0.36+(-1.0)^2=1.36,\\ S_3 &= 0.16+(0.5)^2=0.41. \end{aligned} $$

Therefore, with \(n=3\), the updated random-intercept variance is

$$ D^{\text{new}} = \frac{1.25+1.36+0.41}{3} = \frac{3.02}{3} = 1.007 \text{ score-units squared}. $$

The posterior means alone would give \(\{1.00+1.00+0.25\}/3=0.750\) score-units squared. That is not the EM update: it omits the posterior variances, which sum to \(0.77\) score-units squared across subjects.

Multivariate Updates and Covariance Constraints

With multiple random effects, \(m_i m_i^\mathsf{T}\) contributes both squared posterior means on the diagonal and cross-products off the diagonal. The posterior covariance \(V_i\) contributes uncertainty in each component and posterior dependence between components. Consequently, an off-diagonal entry of \(D^{\text{new}}\) is not just an average product of posterior means: it also includes the corresponding posterior covariance.

Worked Example: Updating an Intercept-Slope Covariance

Consider two hypothetical subjects with a random intercept in score units and a random slope in score units per year. Their posterior summaries, in that order, are

\(m_1=(1.0,0.2)^\mathsf{T}\), \(V_1=\begin{pmatrix}0.25&0.03\\0.03&0.04\end{pmatrix}\), and \(m_2=(-0.5,0.4)^\mathsf{T}\), \(V_2=\begin{pmatrix}0.16&-0.02\\-0.02&0.09\end{pmatrix}\). Treat \(D\) as unstructured.

For subject 1, the outer product of the mean and the second-moment matrix are

$$ m_1m_1^\mathsf{T} = \begin{pmatrix}1.00&0.20\\0.20&0.04\end{pmatrix}, \qquad S_1=V_1+m_1m_1^\mathsf{T} = \begin{pmatrix}1.25&0.23\\0.23&0.08\end{pmatrix}. $$

For subject 2, the corresponding calculations are

$$ m_2m_2^\mathsf{T} = \begin{pmatrix}0.25&-0.20\\-0.20&0.16\end{pmatrix}, \qquad S_2=V_2+m_2m_2^\mathsf{T} = \begin{pmatrix}0.41&-0.22\\-0.22&0.25\end{pmatrix}. $$

Averaging the two second-moment matrices gives

$$ D^{\text{new}} = \frac{S_1+S_2}{2} = \frac{1}{2} \begin{pmatrix}1.66&0.01\\0.01&0.33\end{pmatrix} = \begin{pmatrix}0.830&0.005\\0.005&0.165\end{pmatrix}. $$

The intercept variance is \(0.830\) score-units squared, the slope variance is \(0.165\) score-units squared per year squared, and the intercept-slope covariance is \(0.005\) score-units squared per year. The determinant is \(0.830(0.165)-(0.005)^2=0.136925\), which is positive; with positive diagonal entries, this symmetric two-dimensional matrix is positive definite.

The average-second-moment formula applies directly to an unrestricted covariance matrix. If the model restricts \(D\), the M-step must maximize \(Q_D\) subject to that restriction; one must not retain entries that the model fixes to zero. For example, if \(D\) is constrained to be diagonal, each variance updates to the average of the corresponding diagonal entries of \(S_i\), while all off-diagonal entries of \(D\) remain zero.

Worked Example: Enforcing a Diagonal Covariance

Use the two subjects and posterior moments from the intercept-slope example, but now suppose the model requires the random intercept and random slope to be independent in their population distribution, so \(D\) is diagonal. The unrestricted average had diagonal entries \(0.830\) and \(0.165\), and an off-diagonal entry \(0.005\). Under the diagonal constraint, the update is

$$ D^{\text{new}}_{\text{diagonal}} = \begin{pmatrix} (1.25+0.41)/2 & 0\\ 0 & (0.08+0.25)/2 \end{pmatrix} = \begin{pmatrix} 0.830 & 0\\ 0 & 0.165 \end{pmatrix}. $$

The off-diagonal posterior second moments are not used as an estimated population covariance because the model fixes that covariance to zero. This constraint concerns the population random-effects distribution; it does not require each subject’s posterior covariance to have a zero off-diagonal entry.

Implementation Checks, Alternatives, and Limitations

Before using an update, verify that the posterior summaries are for the same random-effects vector and are evaluated under the same current parameter values. The matrices \(V_i\) should be symmetric and positive semidefinite, up to small numerical error, and the posterior second moments should include both \(V_i\) and \(m_i m_i^\mathsf{T}\). For an unrestricted update, check that the resulting matrix is symmetric and positive semidefinite. A singular estimate can occur at a boundary, even when every posterior covariance calculation is valid; it is not always just a rounding error.

In practice, the posterior moments are often obtained by numerical integration. Insufficient integration accuracy can lead to small asymmetries or invalid covariance matrices. A useful diagnostic is to inspect symmetry and eigenvalues of both the subject-level posterior covariance matrices and the updated \(D\), and to check whether the update changes materially when numerical integration accuracy is increased. If a covariance estimate is near singular, report that issue in the model-fitting process rather than silently replacing it with an unrelated matrix.

The unrestricted update is a closed-form maximizer of the covariance-dependent auxiliary function. A diagonal or otherwise structured covariance requires maximizing that same function under the chosen constraint. This differs from replacing each latent random effect by its posterior mean and calculating an ordinary sample covariance: that plug-in calculation discards posterior uncertainty and may center the values in a way inconsistent with the model’s specified zero prior mean. Direct optimization of the observed-data likelihood is another general estimation strategy, but it does not use this closed-form EM covariance step.

The update also relies on a common covariance \(D\) and a zero prior mean for the random effects. If the model instead estimates a nonzero random-effects mean, or uses subject-specific covariance structures, the relevant complete-data density and auxiliary function change. Likewise, if the covariance is constrained beyond simple diagonal structure, averaging the \(S_i\) matrices need not satisfy the constraint; the constrained maximization must be handled explicitly.

Common mistake: Updating \(D\) by averaging \(m_i m_i^\mathsf{T}\) alone, or by taking the sample covariance of the posterior means, assumes that each latent \(b_i\) is known exactly. The correct unstructured EM update averages \(V_i+m_i m_i^\mathsf{T}\). Posterior variance represents uncertainty about each latent effect and contributes to the expected complete-data second moment.
Key takeaway: For a shared, mean-zero Gaussian random-effects distribution with unrestricted covariance, the M-step sets \(D\) equal to the average posterior second moment. Compute each second moment as posterior covariance plus the outer product of the posterior mean, then impose any model constraints through the appropriate constrained maximization.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. A scalar random effect has posterior mean \(2\) units and posterior variance \(0.5\) units squared for one subject. What is that subject’s posterior second moment?
  2. For a random-effects vector, what two terms make up \(E(b_i b_i^\mathsf{T}\mid O_i)\)? What does each represent?
  3. Two hypothetical subjects have scalar posterior means \(1\) and \(-1\), and posterior variances \(0.2\) and \(0.4\). Under an unrestricted shared zero-mean model, calculate the covariance update.
  4. If the population covariance is constrained to be diagonal, what happens to its off-diagonal entries in the M-step?

Solutions. (1) The second moment is \(0.5+2^2=4.5\) units squared. (2) It is \(V_i+m_i m_i^\mathsf{T}\): \(V_i\) is posterior uncertainty and \(m_i m_i^\mathsf{T}\) is the outer product of the posterior mean. (3) The second moments are \(0.2+1^2=1.2\) and \(0.4+(-1)^2=1.4\) units squared, so the update is \((1.2+1.4)/2=1.3\) units squared. (4) They remain zero because the covariance constraint fixes them to zero; the diagonal entries are updated from the corresponding average posterior second moments.

Clinical Biostats