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.
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\):
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
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.
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:
Therefore, with \(n=3\), the updated random-intercept variance is
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
For subject 2, the corresponding calculations are
Averaging the two second-moment matrices gives
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
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.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- 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?
- For a random-effects vector, what two terms make up \(E(b_i b_i^\mathsf{T}\mid O_i)\)? What does each represent?
- 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.
- 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.