Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › The Longitudinal Density Contribution

Maximum Likelihood and EM Estimation · Tutorial 248 of 697

The Longitudinal Density Contribution

Learn to construct, calculate, and interpret the conditional longitudinal density contribution for Gaussian random-intercept-and-slope models.

Advanced 11 min read

What You'll Learn

  • Write the conditional Gaussian model for repeated measurements with subject-specific random intercepts and slopes.
  • Express a subject’s longitudinal density as a product over observed visits and as a log-likelihood.
  • Calculate a conditional density contribution from hypothetical measurements, times, and model parameters.
  • Distinguish the longitudinal density from the random-effects density and the marginal longitudinal density.
  • Identify assumptions and diagnostics relevant to this contribution, including residual independence and constant variance.

What the Longitudinal Contribution Represents

In a joint model, each subject contributes longitudinal measurements as well as time-to-event information. This tutorial isolates the longitudinal part: the density of a subject’s observed repeated measurements, conditional on that subject’s random intercept and slope. The calculation is a building block for the complete-data likelihood, not a complete joint likelihood by itself.

The key conditioning matters. Once the subject-specific random effects are fixed, the model gives a mean for each observed measurement. The longitudinal density measures how compatible the observed values are with those means and the assumed residual variation. The random-effects density is a separate factor; the marginal longitudinal density instead averages over the random effects.

Definition: For subject \(i\), let \(y_{ij}\) be the longitudinal outcome recorded at time \(t_{ij}\), for \(j=1,\ldots,n_i\). A Gaussian mixed model with a subject-specific random intercept and slope is $$ y_{ij} = \beta_0+\beta_1 t_{ij}+b_{0i}+b_{1i}t_{ij}+\epsilon_{ij}, $$ where \(\beta_0,\beta_1\) are fixed effects, \(b_{0i},b_{1i}\) are the random intercept and slope, and \(\epsilon_{ij}\) is the residual. Conditional on \(b_i=(b_{0i},b_{1i})^\mathsf{T}\), assume the residuals are independent with \(\epsilon_{ij}\sim N(0,\sigma^2)\). The subject-specific conditional mean is \(\mu_{ij}(b_i)=\beta_0+\beta_1t_{ij}+b_{0i}+b_{1i}t_{ij}\).

A standard random-effects specification is \(b_i\sim N(0,D)\), where \(D\) is a \(2\times2\) covariance matrix that allows the random intercept and slope to be correlated. Random effects are typically assumed independent across subjects and independent of the residual errors. These assumptions describe the full mixed model; conditional on a specified \(b_i\), the longitudinal density below depends on \(\sigma^2\) and the conditional means, not directly on \(D\).

The model can also be written in vector form. Let \(y_i=(y_{i1},\ldots,y_{in_i})^\mathsf{T}\), and let \(X_i\) and \(Z_i\) have rows \((1,t_{ij})\). Then \(y_i\mid b_i\) is multivariate normal with mean \(X_i\beta+Z_i b_i\) and covariance \(\sigma^2 I_{n_i}\), where \(\beta=(\beta_0,\beta_1)^\mathsf{T}\). The identity covariance encodes the conditional independence and common residual variance assumptions.

Density and Log-Density

Because the measurements are conditionally independent, the density for subject \(i\) is the product of the normal densities at that subject’s observed visits. Write \(\theta_L\) for the longitudinal parameters, including the fixed effects and residual variance.

$$ f(y_i\mid b_i;\theta_L) = \prod_{j=1}^{n_i} \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left\{-\frac{\left[y_{ij}-\mu_{ij}(b_i)\right]^2}{2\sigma^2}\right\} = (2\pi\sigma^2)^{-n_i/2} \exp\left\{-\frac{1}{2\sigma^2} \sum_{j=1}^{n_i}\left[y_{ij}-\mu_{ij}(b_i)\right]^2\right\}. $$

The second expression follows by multiplying the normalizing constants and adding the exponents. Taking the natural logarithm turns the product into a sum:

$$ \ell_{Li}(b_i;\theta_L) = -\frac{n_i}{2}\log(2\pi\sigma^2) -\frac{1}{2\sigma^2} \sum_{j=1}^{n_i}\left[y_{ij}-\mu_{ij}(b_i)\right]^2. $$

Thus, given the parameters and \(b_i\), the longitudinal contribution is determined by the number of observed measurements and the sum of squared conditional residuals. A subject with more observations contributes more normalizing terms and more residual terms. Different subjects may have different \(n_i\); the product is over the visits actually observed for each subject.

Worked Example: One Subject’s Conditional Density

Suppose a hypothetical subject has measurements \(y=(10,12,11)\) at times \(t=(0,1,2)\). Use \(\beta_0=10\), \(\beta_1=1\), \(b_{0i}=1\), \(b_{1i}=-0.5\), and \(\sigma=0.5\). Calculate the subject’s conditional density and log-density.

At time \(t\), the conditional mean is \(10+t+1-0.5t=11+0.5t\). The means at the three visits are therefore \(11,11.5,12\), giving residuals \(10-11=-1\), \(12-11.5=0.5\), and \(11-12=-1\). Their squared sum is \(1+0.25+1=2.25\).

Substituting into the product density gives $$ f(y_i\mid b_i) =(\sqrt{2\pi}\,0.5)^{-3} \exp\left\{-\frac{2.25}{2(0.5)^2}\right\} =(0.7979)^3 e^{-4.5} \approx 0.00564. $$

The corresponding log-density is $$ \ell_{Li} =-3\log(\sqrt{2\pi}\,0.5)-\frac{2.25}{0.5} \approx -0.6774-4.500=-5.177. $$ This density is expressed per three outcome measurements, in the inverse units of their joint measurement scale. The log-density is a numerical likelihood contribution, not a probability that the specified model is true.

How the Formula Follows From the Assumptions

For a single visit, conditional normality gives the density $$ f(y_{ij}\mid b_i;\theta_L) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left\{-\frac{[y_{ij}-\mu_{ij}(b_i)]^2}{2\sigma^2}\right\}. $$ Conditional independence means the joint density of all \(n_i\) observed measurements is the product of these \(n_i\) terms. Multiplying the constants yields \((2\pi\sigma^2)^{-n_i/2}\); multiplying exponentials adds their exponents, yielding the squared-residual sum divided by \(2\sigma^2\). Taking the logarithm gives the stated log-density because \(\log(ab)=\log(a)+\log(b)\) and \(\log(e^x)=x\). These steps also show why changing the residual distribution or dependence assumptions changes the contribution.

Worked Example: Unequally Spaced Visits

For a hypothetical subject observed at \(t=0\) and \(t=2\), let \(y=(5,3.5)\), \(\beta_0=5\), \(\beta_1=0.5\), \(b_{0i}=-1\), \(b_{1i}=0.25\), and \(\sigma=1\). Find the conditional log-density and density.

The conditional mean is \(5+0.5t-1+0.25t=4+0.75t\), so the means are \(4\) at \(t=0\) and \(5.5\) at \(t=2\). The residuals are \(1\) and \(-2\), with squared sum \(1+4=5\). The fact that the times are unequally spaced does not alter the formula; their values enter through the conditional means.

With \(n_i=2\) and \(\sigma=1\), $$ \ell_{Li} =-\log(2\pi)-\frac{5}{2} \approx -1.8379-2.500=-4.338. $$ The density is $$ f(y_i\mid b_i) =(2\pi)^{-1}\exp(-2.5) \approx 0.01306. $$

This calculation assumes the same residual variance at both visits and conditional independence, despite the gap between the visit times. Unequal spacing is allowed; serial correlation or a time-varying residual variance would require a different covariance model.

Combining Subjects and Keeping Contributions Separate

Conditional on the random effects for all subjects, and assuming independent subjects’ residual processes, the full longitudinal conditional likelihood is the product of the subject contributions. Its log is the sum of their log-densities. In the complete-data joint likelihood, each subject’s random-effects density is also included. Do not fold that density into the conditional longitudinal contribution: it is a distinct factor.

The distinction from the marginal longitudinal likelihood is also important. The marginal density for \(y_i\) averages the conditional density over the distribution of \(b_i\); it is not obtained by simply setting \(b_i=0\). The earlier material on marginal likelihood by integrating random effects treats that integration. Here the target is specifically the conditional density evaluated at a given random-effects value.

Worked Example: Adding Two Subjects’ Contributions

Consider two hypothetical subjects under \(\beta_0=2\), \(\beta_1=0.4\), and \(\sigma=1.5\). Subject 1 has \(t=(0,1)\), \(b_1=(0.2,-0.1)^\mathsf{T}\), and \(y=(2.7,1.5)\). Subject 2 has \(t=(0,1,2)\), \(b_2=(-0.3,0.2)^\mathsf{T}\), and \(y=(0.7,2.8,2.9)\). Calculate the combined conditional longitudinal log-likelihood.

For subject 1, the means are \(2+0.2=2.2\) and \(2+0.4+0.2-0.1=2.5\). The residuals are \(0.5,-1\), so the squared sum is \(0.25+1=1.25\). For subject 2, the means are \(2-0.3=1.7\), \(2+0.4-0.3+0.2=2.3\), and \(2+0.8-0.3+0.4=2.9\). The residuals are \(-1,0.5,0\), also giving a squared sum of \(1.25\).

There are five observations in total and the combined squared-residual sum is \(2.50\). Therefore, $$ \ell_L =-\frac{5}{2}\log(2\pi(1.5)^2)-\frac{2.50}{2(1.5)^2} =-5\log(3.7599)-0.5556 \approx -7.178. $$

Equivalently, the two subject log-densities are added: each has two or three observations, respectively, and each has squared-residual sum \(1.25\). This sum is the longitudinal conditional part only; it does not include either subject’s random-effects density.

Assumptions, Diagnostics, and Alternatives

The formula is appropriate when the conditional mean is linear in time with the specified random intercept and slope, residuals are Gaussian with mean zero, residual variance is \(\sigma^2\) at every visit, and residuals are independent conditional on the random effects. For the usual mixed model, one also specifies a distribution for the random effects, commonly a mean-zero bivariate normal with covariance \(D\). That random-effects assumption is needed for the full model and marginalization, but not to evaluate the conditional Gaussian density at fixed \(b_i\).

Diagnostics should assess whether the assumptions are plausible rather than treating the density formula as proof that they hold. Conditional residuals \(y_{ij}-\mu_{ij}(b_i)\) can be inspected for trends over time, changing spread, skewness, outliers, or serial patterns. A pattern in residuals may indicate an inadequate mean trajectory, omitted structure, nonconstant variance, or residual dependence. In practice, random effects are estimated rather than known, so residual diagnostics inherit that estimation uncertainty. The conditional density alone also does not determine whether a missing-measurement or dropout process is ignorable.

The main alternatives answer different modeling questions. A marginal longitudinal density integrates over the random-effects distribution and describes the response distribution without conditioning on a particular subject effect. A conditional model with correlated or heteroscedastic residuals replaces \(\sigma^2 I_{n_i}\) with a more general residual covariance matrix; then the multivariate normal density includes its determinant and inverse. A model with a different trajectory or non-Gaussian outcomes also requires a different conditional density. These are not interchangeable calculations: the chosen contribution must match the assumed data-generating model.

Common pitfall: Setting \(b_i=0\) and calling the resulting density the marginal contribution is incorrect. It evaluates the conditional density for a subject whose random effects are exactly zero. The marginal density averages \(f(y_i\mid b_i)\) over the distribution of \(b_i\), and in general that average is not equal to \(f(y_i\mid b_i=0)\).

A second practical error is omitting the normalizing constant when comparing likelihoods that involve different residual variances or different numbers of measurements. The term \(-n_i\log(2\pi\sigma^2)/2\) depends on \(\sigma^2\), so it cannot be dropped when estimating that parameter. Even when constants independent of the parameters may be omitted for a particular optimization, retaining the full expression reduces ambiguity and makes contributions easier to verify.

Check Your Understanding

Answer each question using the conditional Gaussian random-intercept-and-slope model above. Short solutions follow the questions.

  1. If a subject has four observed measurements, what is the exponent on the normalizing factor in the conditional density?
  2. For residuals \(1\) and \(-1\) with \(\sigma=2\), what is the residual-sum contribution to the log-density?
  3. Does the conditional longitudinal density at a fixed \(b_i\) directly include the random-effects covariance matrix \(D\)?
  4. Why is evaluating the conditional density at \(b_i=0\) not generally the same as calculating the marginal density?
  5. Name one assumption whose failure would make the product of independent univariate normal densities inappropriate.

Solutions. (1) The exponent is \(-n_i/2=-2\), so the normalizing factor is \((2\pi\sigma^2)^{-2}\). (2) The squared-residual sum is \(1^2+(-1)^2=2\); its log-density contribution is \(-2/[2(2^2)]=-0.25\). (3) No. At fixed \(b_i\), \(D\) belongs to the separate random-effects density; the conditional response density uses the means and \(\sigma^2\). (4) The marginal density averages the conditional density over the random-effects distribution, whereas \(b_i=0\) evaluates it at one particular value. Averaging and evaluating at zero are generally different operations. (5) For example, serially correlated residuals violate conditional independence, while nonconstant residual variance violates the common-\(\sigma^2\) assumption.

Clinical Biostats