Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › From Subject Contributions to the Sample Log Likelihood

Maximum Likelihood and EM Estimation · Tutorial 253 of 697

From Subject Contributions to the Sample Log Likelihood

Learn to assemble subject-specific marginal likelihoods and combine them correctly into a sample log likelihood with unequal numbers of longitudinal measurements.

Advanced 10 min read

What You'll Learn

  • Write a longitudinal likelihood when each subject has a different number of visits.
  • Combine longitudinal and event-time terms conditional on a subject’s random effects.
  • Define a subject’s marginal contribution by averaging over the random-effects distribution.
  • Derive the sample log likelihood from independent subject contributions.
  • Account for delayed entry and recognize common implementation errors.
  • Check likelihood calculations using subject-level diagnostics.

From Individual Records to a Sample Objective

A joint model is built from information recorded on each subject: a sequence of longitudinal measurements and an event time, possibly right-censored. The model first describes the data for one subject, including the unobserved random effects that link that subject’s measurements and event risk. For estimation from a sample, the subject-specific random effects are not observed, so each subject’s likelihood contribution must average over their distribution. Independent subjects’ marginal contributions then multiply, and taking logarithms turns that product into a sum.

The accounting is important when subjects have different numbers of visits. Each subject contributes the measurements actually observed for that subject—not a product padded to a common visit count. The number and timing of visits may differ without changing the basic rule for combining independent subjects.

Subject-Level Data and Likelihood

Let \(i=1,\ldots,N\) index subjects. Subject \(i\) has longitudinal measurements \(Y_{ij}\) at visit times \(t_{ij}\), for \(j=1,\ldots,n_i\), where \(n_i\) may vary across subjects. Let \(T_i\) denote the observed event or censoring time, and let \(\delta_i=1\) indicate an event and \(\delta_i=0\) indicate right censoring. Write \(b_i\) for the subject’s random-effects vector and \(\theta\) for all model parameters, including longitudinal, event-time, association, and random-effects parameters.

Conditional on \(b_i\), the longitudinal model supplies a density for the measurements. For example, if measurements are conditionally independent given \(b_i\), their contribution is the product of their individual conditional densities. The event-time model supplies a conditional hazard \(h_i(t\mid b_i;\theta)\) and survival function \(S_i(t\mid b_i;\theta)\). Under the usual right-censoring likelihood, the event-time contribution is the hazard at the observed time for an event, multiplied by survival through that time:

$$ L_{Ti}(\theta\mid b_i) = h_i(T_i\mid b_i;\theta)^{\delta_i} S_i(T_i\mid b_i;\theta). $$

This expression assumes censoring is noninformative for the event-time process conditional on the modeled information, and that the event and censoring times are observed according to the specified scheme. When \(\delta_i=1\), the contribution is \(h_i(T_i\mid b_i;\theta)S_i(T_i\mid b_i;\theta)\), the event-time density. When \(\delta_i=0\), it is \(S_i(T_i\mid b_i;\theta)\), the probability of surviving beyond the censoring time. The longitudinal and event-time observations are modeled as conditionally independent given the random effects and included covariates; their dependence after averaging over \(b_i\) is part of the joint model.

Definition: With no delayed entry, the conditional joint-data contribution for subject \(i\) is $$ L_i(\theta\mid b_i) = \left\{\prod_{j=1}^{n_i} f_Y(Y_{ij}\mid b_i,t_{ij};\theta)\right\} h_i(T_i\mid b_i;\theta)^{\delta_i} S_i(T_i\mid b_i;\theta). $$ The subject’s marginal likelihood contribution is $$ L_i(\theta) = \int L_i(\theta\mid b_i)f_b(b_i;\theta)\,db_i, $$ where \(f_b\) is the random-effects density. The sample likelihood for independent subjects is \(L(\theta)=\prod_{i=1}^N L_i(\theta)\), and the sample log likelihood is \(\ell(\theta)=\sum_{i=1}^N\log L_i(\theta)\).

The integral is over the random-effects vector for one subject. It produces a marginal contribution for that subject’s observed data; it does not mean the subject has one shared random effect with every other subject. The sample factorization requires independent subjects under the sampling model and independent subject-level random effects. Within a subject, the repeated measurements need not be marginally independent: shared random effects generally induce dependence among them and connect the longitudinal and event-time outcomes.

The visit count enters through the limits of the product. If subject A has \(n_A=2\) visits and subject B has \(n_B=4\), their longitudinal factors have two and four terms, respectively. There is no requirement to force both subjects into a product with the same number of terms. Visit times can also differ, provided their role in the conditional density is specified. This likelihood treats the observed visit schedule as fixed or conditioned upon; if the observation process itself is informative, its model may need to be included.

Worked Example: A Conditional Contribution With Two Visits

Suppose a hypothetical subject has two measurements, \(Y_{i1}=1.4\) at \(t_{i1}=1\) and \(Y_{i2}=1.8\) at \(t_{i2}=3\). At a particular random-effects value \(b_i\) and parameter value \(\theta\), suppose the longitudinal model gives conditional densities \(0.7365\) and \(0.7821\), respectively. Suppose this subject has an event at \(T_i=4\), with \(h_i(4\mid b_i;\theta)=0.30\) per year and \(S_i(4\mid b_i;\theta)=0.40\). The conditional contribution is

$$ L_i(\theta\mid b_i) = (0.7365)(0.7821)(0.30)(0.40) \approx 0.06912. $$

The longitudinal product is \(0.7365\times0.7821=0.57601665\), which rounds to \(0.5760\). The event-time factor is \(0.30\times0.40=0.12\), so the full conditional contribution is \(0.57601665\times0.12=0.069121998\), or approximately \(0.06912\). The hazard has units of inverse years; densities and likelihood contributions may carry units as well, so their numerical values are not probabilities by themselves. This calculation is conditional on the stated \(b_i\); the marginal contribution still requires averaging over \(f_b\).

Why the Sample Log Likelihood Is a Sum

The result follows directly from independence. Given \(\theta\), independent subjects have a joint density equal to the product of their marginal densities. Each marginal density is the contribution \(L_i(\theta)\) obtained after integrating over that subject’s random effects. Thus \(L(\theta)=\prod_i L_i(\theta)\). For positive contributions, the logarithm of a product is the sum of the logarithms:

$$ \ell(\theta) = \log\left\{\prod_{i=1}^N L_i(\theta)\right\} = \sum_{i=1}^N\log L_i(\theta). $$

This is the sample log likelihood to be maximized with respect to \(\theta\). It is a sum over subjects, not a sum over visits alone: each subject’s measurements and event information are first assembled inside that subject’s marginal contribution. In particular, one must not integrate the random effects separately for each visit. Doing so would replace the shared subject-level random effect with visit-specific effects and would specify a different model.

Worked Example: Combining Unequal Visit Counts

Consider three hypothetical independent subjects. Subject 1 has two visits, subject 2 has four, and subject 3 has one. At a fixed \(\theta\), suppose their fully marginal contributions—each already incorporating the subject’s longitudinal and event-time data and integrating over that subject’s random effects—are \(L_1=0.012\), \(L_2=0.004\), and \(L_3=0.020\). Then

$$ L(\theta)=(0.012)(0.004)(0.020)=0.00000096. $$

Taking logs by subject is more stable and gives

$$ \ell(\theta) = \log(0.012)+\log(0.004)+\log(0.020) = -4.42285-5.52146-3.91202 = -13.85633. $$

The differing visit counts do not require a correction factor: they are already reflected in each subject’s contribution. The product is very small, while the log likelihood is a manageable sum. The numbers are illustrative likelihood contributions, not probabilities that must sum to one.

Delayed Entry in the Subject Contribution

When a subject enters observation at time \(E_i\), inclusion requires that the subject remain event-free through entry. Under a likelihood conditioned on this delayed-entry criterion, the event contribution conditional on \(b_i\) is \(h_i(T_i\mid b_i;\theta)^{\delta_i}S_i(T_i\mid b_i;\theta)/S_i(E_i\mid b_i;\theta)\). However, after integrating over random effects, conditioning on entry must be handled at the marginal subject level. The selection event changes the distribution of random effects among enrolled subjects. Therefore the conditional marginal contribution is the joint marginal density divided by the marginal probability of surviving to entry:

$$ L_i^{(E)}(\theta) = \frac{ \displaystyle \int \left\{\prod_{j=1}^{n_i} f_Y(Y_{ij}\mid b_i,t_{ij};\theta)\right\} h_i(T_i\mid b_i;\theta)^{\delta_i} S_i(T_i\mid b_i;\theta) f_b(b_i;\theta)\,db_i }{ \displaystyle \int S_i(E_i\mid b_i;\theta)f_b(b_i;\theta)\,db_i }. $$

This form assumes the observed longitudinal record is included in the joint numerator and that the entry condition is \(T_i>E_i\). The denominator is the marginal probability of being event-free at entry under the model. In general, it is not correct to divide the event factor by \(S_i(E_i\mid b_i;\theta)\) after integrating as though the random-effects distribution among entrants were unchanged. The sample log likelihood for the enrolled subjects is again the sum of the logs of their conditional marginal contributions, \(\sum_i\log L_i^{(E)}(\theta)\), under independent subject sampling conditional on the specified entry scheme.

Worked Example: Summing Contributions Conditional on Entry

Suppose two hypothetical subjects entered at different times and had different visit counts. At a fixed \(\theta\), assume the numerator and denominator integrals in the delayed-entry expression evaluate to \(0.018\) and \(0.60\) for subject 1, and \(0.011\) and \(0.55\) for subject 2. These values are stipulated outputs of the subject-level integrations. Their conditional contributions are

$$ L_1^{(E)}=\frac{0.018}{0.60}=0.0300, \qquad L_2^{(E)}=\frac{0.011}{0.55}=0.0200. $$

The conditional sample likelihood and log likelihood are

$$ L^{(E)}(\theta)=(0.0300)(0.0200)=0.000600, \qquad \ell^{(E)}(\theta)=\log(0.0300)+\log(0.0200) =\log(0.000600)\approx-7.4186. $$

The denominator corrects each subject’s contribution for the relevant entry condition; it does not create a common denominator for the sample. Different entry times, like different visit counts, are accommodated within the corresponding subject-level terms.

Implementation Checks and Common Pitfalls

The factorization is simple, but errors in the subject-level terms can change the model being fitted. Before maximizing the objective, check that every subject has exactly the observed number of longitudinal factors, the correct event indicator, and the correct time and covariates. Check that each marginal contribution is positive and finite; its logarithm must therefore be defined. When evaluating contributions numerically, retain adequate precision through integration and take the log of each contribution before summing when possible. A tiny product of many valid contributions can underflow in ordinary floating-point arithmetic even though the sum of their logs remains representable.

A useful diagnostic is to inspect subject-level log contributions across plausible parameter values. Unexpected nonfinite values, abrupt changes caused by a coding boundary, or contributions inconsistent with a subject’s event status can reveal indexing errors, a missing survival term, or an incorrect censoring indicator. Also verify that visit indices run only from \(1\) to \(n_i\), rather than to a common maximum for every subject. If padded records are used in software, padded entries must not be treated as observed measurements.

  • Wrong: Multiply all observed measurements and event terms across all subjects first, then integrate over one random effect. Correction: Each subject has their own random effect. Form and marginalize each subject’s contribution, then multiply the resulting contributions.
  • Wrong: Use the same number of longitudinal density factors for every subject. Correction: Use \(n_i\) factors for subject \(i\); unequal visit counts are expected.
  • Wrong: Add the raw likelihood contributions. Correction: Independent contributions multiply on the likelihood scale and add only after taking logarithms.
  • Wrong: Treat a censored time as an event. Correction: With \(\delta_i=0\), the event-time factor is survival through \(T_i\), without a hazard multiplier.
  • Wrong: Apply delayed-entry conditioning after marginalization by dividing by an arbitrary subject-specific conditional survival value. Correction: Use the appropriate marginal probability of meeting the entry condition in the denominator.

The main alternative representation is the conditional or complete-data likelihood, which retains the random effects rather than integrating them out. That representation can be useful in estimation procedures that treat random effects as latent variables, but it is not the observed-data marginal likelihood defined here. Another tempting shortcut is to multiply conditional likelihoods across visits as if measurements were marginally independent. That loses the shared random-effects structure. The marginal likelihood retains it, although its integrals may require numerical evaluation in practice. The specific integration methods and approximations are separate computational choices; they do not alter the subject-product and log-sum identities.

These identities rely on the sampling assumptions. If subjects are clustered with shared latent effects, or otherwise dependent after conditioning on modeled parameters, the sample likelihood need not factor into independent subject terms. Similarly, informative observation times or a misspecified censoring or entry mechanism can invalidate the stated contribution. The sample log likelihood is only as appropriate as the model and observation scheme used to construct its subject terms.

Key takeaway: Build one conditional joint contribution per subject, integrate over that subject’s random-effects distribution, and then combine the marginal contributions as a product—or, equivalently, add their logarithms. Each subject’s own visit count and entry condition belong in that subject’s term.

Check Your Understanding

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

  1. Two independent subjects have marginal contributions \(0.05\) and \(0.10\). What are their combined likelihood and log likelihood?
  2. A subject has three visits and is right-censored at time \(T_i\). How many longitudinal density factors appear, and what is the event-time factor?
  3. Why is integrating a single random effect after multiplying contributions from all subjects generally incorrect?
  4. With delayed entry, what event defines the denominator of a subject’s conditional marginal likelihood?

Solutions. (1) The combined likelihood is \((0.05)(0.10)=0.005\), and its log is \(\log(0.05)+\log(0.10)=\log(0.005)\approx-5.2983\). (2) There are three longitudinal factors, \(\prod_{j=1}^{3}f_Y(Y_{ij}\mid b_i,t_{ij};\theta)\). Since \(\delta_i=0\), the event-time factor is \(S_i(T_i\mid b_i;\theta)\), with no hazard multiplier. (3) Independent subjects have separate subject-level random effects. Integrating one common effect would induce a shared latent effect across subjects and would not represent the stated model; instead, integrate each subject’s contribution over that subject’s random-effects distribution. (4) The denominator is the marginal probability of satisfying the entry condition, here \(P(T_i>E_i)=\int S_i(E_i\mid b_i;\theta)f_b(b_i;\theta)\,db_i\).

Clinical Biostats