Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Computing Posterior Class Probabilities

Latent Class Joint Models · Tutorial 448 of 697

Computing Posterior Class Probabilities

Learn how Bayes’ rule combines class priors, longitudinal data, and survival information to calculate a subject’s probability of belonging to each latent trajectory class.

Advanced 11 min read

What You'll Learn

  • Define class-specific likelihood contributions for longitudinal measurements and event or right-censoring history.
  • Derive posterior class probabilities by normalizing prior-weighted likelihoods.
  • Calculate posterior probabilities for censored and observed-event examples.
  • Assess how baseline covariates and survival information alter class probabilities.
  • Identify assumptions, numerical diagnostics, and common classification errors.

Why Compute Posterior Class Probabilities?

A latent class joint model represents a population as a mixture of unobserved trajectory groups. Before seeing a subject’s data, the model assigns probabilities to class membership. After observing that subject’s longitudinal measurements and event history, those probabilities can change: a trajectory may fit one class better, while survival up to a censoring time or an observed event may favor another. Posterior class probabilities quantify this subject-specific update.

The calculation is a direct application of Bayes’ rule to the observed-data mixture likelihood. It is important to include the whole observed history specified by the model. Using only the biomarker trajectory, for example, discards survival information that may distinguish classes.

Definition and Assumptions

Definition: Let \(C_i\) be subject \(i\)’s unobserved class, taking values \(g=1,\ldots,G\), and let \(X_i\) denote their baseline covariates. Write \(\pi_{ig}=P(C_i=g\mid X_i)\) for the class prior probability. Let \(Y_i\) be the subject’s observed longitudinal measurements, \(\tilde T_i\) the observed event or censoring time, and \(\delta_i\) the event indicator, equal to 1 for an observed event and 0 for right censoring. The posterior class probability is \[ \tau_{ig}=P(C_i=g\mid Y_i,\tilde T_i,\delta_i,X_i). \]

For each class, the observed longitudinal data have a class-specific density or probability mass \(f_g(Y_i\mid X_i)\). Let \(h_g(t\mid X_i)\) and \(S_g(t\mid X_i)\) be the event hazard and event-free survival function in class \(g\). Under right censoring, the event-history contribution is

$$ q_{ig}=h_g(\tilde T_i\mid X_i)^{\delta_i} S_g(\tilde T_i\mid X_i). $$

Thus, for an observed event, the contribution is \(h_g(\tilde T_i\mid X_i)S_g(\tilde T_i\mid X_i)\), the event-time density implied by the hazard and survival. For right censoring, it is \(S_g(\tilde T_i\mid X_i)\): the subject is known to have remained event-free through that time, but their event time is not observed.

The basic calculation uses the factorization of the observed-data likelihood: conditional on class and modeled covariates, the longitudinal and event histories contribute \(f_g(Y_i\mid X_i)\) and \(q_{ig}\), respectively. It also assumes that the censoring mechanism can be omitted from the class comparison—for example, because censoring is conditionally independent and its contribution does not vary by class. If censoring is informative in a way not captured by the model, or has a class-specific likelihood contribution, the posterior calculation must account for that mechanism. The longitudinal observation process must likewise be ignorable under the model being used.

Bayes’ Rule and Its Justification

Define the unnormalized class weight \(w_{ig}\) as the prior class probability multiplied by the likelihood of subject \(i\)’s observed data under that class. The denominator in Bayes’ rule sums these weights over all possible classes:

$$ w_{ig}=\pi_{ig} f_g(Y_i\mid X_i)q_{ig}, \qquad \tau_{ig}= \frac{w_{ig}}{\sum_{k=1}^G w_{ik}} = \frac{\pi_{ig} f_g(Y_i\mid X_i) h_g(\tilde T_i\mid X_i)^{\delta_i}S_g(\tilde T_i\mid X_i)} {\sum_{k=1}^G \pi_{ik} f_k(Y_i\mid X_i) h_k(\tilde T_i\mid X_i)^{\delta_i}S_k(\tilde T_i\mid X_i)}. $$

To see why, the joint probability or density of class \(g\) and the observed history, conditional on \(X_i\), is the prior probability \(\pi_{ig}\) times the class-specific observed-data likelihood. The marginal probability or density of the observed history is obtained by summing this joint contribution across the mutually exclusive classes. Dividing the class-specific joint contribution by that marginal gives the conditional probability of class \(g\). Consequently, every \(\tau_{ig}\) is nonnegative and the probabilities sum to one, provided the observed history has positive total likelihood under the model.

The numerator is a weight, not yet a probability: it has not been normalized across classes. The longitudinal density can have measurement units, and the event density for an observed event has inverse-time units, but these factors are common in their units across classes. After normalization, the posterior class probabilities are dimensionless.

Worked Example: A Right-Censored Subject

Consider two classes with prior probabilities \(\pi_{i1}=0.60\) and \(\pi_{i2}=0.40\). Suppose the longitudinal data have class-specific densities \(f_1(Y_i)=0.080\) and \(f_2(Y_i)=0.200\), in the same measurement-density units. The subject is event-free at the censoring time of 2 years. Assume exponential event times with class-specific hazards \(0.20\) and \(0.80\) per year, so \(S_g(t)=\exp(-\lambda_g t)\). The prior probabilities are nonnegative and sum to one; the exponential hazards are positive; and, for this example, censoring is assumed independent conditional on the modeled information.

Because the subject is censored, \(\delta_i=0\), so the event-history contribution is survival alone:

$$ S_1(2)=e^{-0.20(2)}=e^{-0.4}=0.670320, \qquad S_2(2)=e^{-0.80(2)}=e^{-1.6}=0.201897. $$

The unnormalized weights are

$$ w_{i1}=0.60(0.080)(0.670320)=0.0321754, \qquad w_{i2}=0.40(0.200)(0.201897)=0.0161518. $$

Their total is \(0.0321754+0.0161518=0.0483272\). Using these unrounded weights, the posterior probabilities are

$$ \tau_{i1}=\frac{0.0321754}{0.0483272}=0.6658, \qquad \tau_{i2}=\frac{0.0161518}{0.0483272}=0.3342. $$

The longitudinal density favors class 2, but surviving event-free for 2 years favors class 1, whose hazard is lower. Combining both sources of information gives a posterior probability of about 0.6658 for class 1. This is a model-based probability conditional on the recorded history and assumptions; it does not establish that class membership is known with certainty.

Observed Events and Baseline Covariates

Worked Example: An Observed Event

Suppose two classes have equal prior probabilities. The longitudinal density for the observed measurements is \(0.120\) in class 1 and \(0.060\) in class 2. The subject has an event at 1.5 years. Assume exponential hazards of \(0.30\) and \(0.90\) events per year in classes 1 and 2, respectively. These are positive, class-specific constant hazards, and the event is observed rather than censored, so \(\delta_i=1\).

For exponential event times, \(h_g(t)S_g(t)=\lambda_g e^{-\lambda_g t}\). At 1.5 years the event-time contributions are

$$ q_{i1}=0.30e^{-0.30(1.5)}=0.30e^{-0.45}=0.191288, \qquad q_{i2}=0.90e^{-0.90(1.5)}=0.90e^{-1.35}=0.233316. $$

The weights and normalized probabilities are

$$ w_{i1}=0.50(0.120)(0.191288)=0.0114773, \qquad w_{i2}=0.50(0.060)(0.233316)=0.0069995, $$ $$ \sum_g w_{ig}=0.0184768, \qquad \tau_{i1}=\frac{0.0114773}{0.0184768}=0.6212, \qquad \tau_{i2}=\frac{0.0069995}{0.0184768}=0.3788. $$

The event contribution is larger in class 2, which has the higher hazard, while the longitudinal density is twice as large in class 1. After both contributions are included, class 1 has posterior probability 0.6212. An event at a particular time is not represented by survival alone: omitting the hazard would discard the information that an event occurred at that time.

Worked Example: Updating Class Probabilities With a Baseline Covariate

Suppose class membership depends on a binary baseline covariate \(X_i=1\), with a two-class logistic model

$$ \operatorname{logit}(\pi_{i1})=-1+1.5X_i, \qquad \pi_{i2}=1-\pi_{i1}. $$

For \(X_i=1\), \(\pi_{i1}=e^{0.5}/(1+e^{0.5})=0.622459\), and \(\pi_{i2}=0.377541\). Assume the longitudinal density values are \(0.040\) and \(0.100\), and the subject is censored at a time when the class-specific survival probabilities are \(0.800\) and \(0.300\). These survival values lie between zero and one, and the censoring contribution is survival because \(\delta_i=0\). The weights are

$$ w_{i1}=0.622459(0.040)(0.800)=0.0199187, \qquad w_{i2}=0.377541(0.100)(0.300)=0.0113262. $$

The total is \(0.0312449\), giving \(\tau_{i1}=0.0199187/0.0312449=0.6375\) and \(\tau_{i2}=0.3625\). If survival information were omitted, the longitudinal-only class 1 probability would instead be

$$ \frac{0.622459(0.040)} {0.622459(0.040)+0.377541(0.100)} = \frac{0.0248984}{0.0626525} =0.3974. $$

Here, the observed survival history substantially shifts the posterior toward class 1. The prior from baseline covariates is the starting point, not a substitute for the subject-specific likelihood.

Practical Calculation and Diagnostics

For many classes or long records, class likelihoods can be very small. Direct multiplication may underflow numerically, producing zeros even when the true likelihoods are positive. A stable alternative is to calculate log weights:

$$ a_{ig}=\log(\pi_{ig})+\log f_g(Y_i\mid X_i) +\delta_i\log h_g(\tilde T_i\mid X_i) +\log S_g(\tilde T_i\mid X_i). $$

If \(m_i=\max_g a_{ig}\), then normalize using

$$ \tau_{ig}= \frac{\exp(a_{ig}-m_i)} {\sum_{k=1}^G \exp(a_{ik}-m_i)}. $$

Subtracting the same number \(m_i\) from every log weight leaves the ratios unchanged, while keeping the exponentials in a safer numerical range. This calculation requires finite log contributions for classes with positive weight. If a prior is zero, that class’s posterior is zero and its log weight can be treated as negative infinity.

  • Check normalization. Verify that all posterior probabilities are between zero and one and that \(\sum_g\tau_{ig}=1\), up to rounding.
  • Check event coding. Confirm that an observed event includes the hazard term, while right censoring contributes survival only.
  • Check the denominator. If every weight is zero or nonfinite, investigate the likelihood calculation, data coding, and model support. Normalization cannot repair an impossible or numerically corrupted likelihood.
  • Check the conditioning assumptions. If censoring or the measurement schedule depends on class beyond the modeled information, omitting its contribution can distort posterior probabilities.

Posterior probabilities are useful for describing which classes are relatively compatible with a subject’s observed record. Assigning the subject to the class with the largest posterior probability is a separate hard-classification decision; it discards uncertainty. Nor should a large posterior be treated as proof that the class is a real, directly observed subgroup. These probabilities are conditional on the fitted model and its assumptions.

Common Pitfall and Alternatives

A common mistake is to multiply each class likelihood by the prior and then report those unnormalized products as posterior probabilities. For example, weights \(0.03\) and \(0.02\) are not probabilities summing to one. The correction is to divide each weight by the sum across all classes: the corresponding probabilities are \(0.03/0.05=0.60\) and \(0.02/0.05=0.40\).

Another tempting alternative is to classify using only the longitudinal trajectory or only the event history. A trajectory-only calculation uses \(\pi_{ig}f_g(Y_i\mid X_i)\); an event-only calculation uses \(\pi_{ig}q_{ig}\). Either can be useful as a comparison or when the other data source is unavailable, but neither is the posterior based on the full history in a joint model. The full posterior combines the sources specified in the model. Its main limitation is that it inherits model misspecification: incorrect class-specific trajectories, hazards, covariate effects, or censoring assumptions can lead to misleading probabilities.

Key takeaway: A subject’s posterior class probability is the class prior multiplied by that class’s likelihood for the observed longitudinal and event history, divided by the sum of those products across classes.

Check Your Understanding

Work through the questions, then compare your reasoning with the solutions below.

  1. A subject is right-censored at time \(t\). Which class-specific event-history contribution belongs in the posterior weight, and why?
  2. Two classes have unnormalized weights \(0.018\) and \(0.042\). Calculate both posterior probabilities.
  3. For an observed event, why is the event-history contribution not just \(S_g(\tilde T_i)\)?
  4. Suppose the longitudinal data favor class 1 but the survival contribution favors class 2. Must the joint posterior favor either class automatically? Explain.

Solutions. (1) Use \(S_g(t)\), because censoring establishes that the subject remained event-free through \(t\), without revealing an event at \(t\). (2) The total weight is \(0.018+0.042=0.060\); the probabilities are \(0.018/0.060=0.300\) and \(0.042/0.060=0.700\). (3) An observed event at time \(t\) contributes the event-time density \(h_g(t)S_g(t)\); survival alone describes being event-free through \(t\). (4) No. The posterior depends on the products of the prior and all class-specific likelihood contributions, so the relative sizes of the combined weights determine which class has the larger posterior.

Clinical Biostats