Why Nonlinear Association Terms Need Careful Sampling
In a joint model, the survival hazard can depend on a latent longitudinal trajectory rather than only on observed biomarker measurements. A nonlinear association, such as dependence on the trajectory squared, changes both the hazard at the event time and the cumulative hazard accumulated before that time. Consequently, it changes the posterior density and its gradients with respect to the latent random effects. A sampler that evaluates the event-time term correctly but approximates or differentiates the cumulative term incorrectly targets the wrong posterior.
This tutorial develops the computation for a squared current-value association. The same chain-rule principles apply to other differentiable nonlinear functions, but their mathematical and numerical behavior must be checked for the chosen function.
The squared term is a modeling choice, not a universal default. It makes the hazard respond to the magnitude of the latent value: for positive \(\alpha\), values farther from zero increase the hazard, whether they are positive or negative. If a trajectory has a meaningful reference level, it may be more interpretable to square a centered value. Units matter: if \(m_i(t)\) is measured in biomarker units, \(\alpha\) has inverse squared-biomarker units so that the exponent is dimensionless.
Likelihood and Posterior Target
Conditional on the random effects and model parameters, the longitudinal measurements and event process are modeled as conditionally independent. For example, a Gaussian longitudinal model has \(Y_{ij}\mid b_i,\beta,\sigma^2\sim N(m_i(t_{ij}),\sigma^2)\). The event contribution, conditional on \(b_i\), is
The event indicator removes the event-time hazard factor for a censored subject, but the cumulative-hazard term remains. Taking logarithms gives
The joint posterior is proportional to the product of these survival contributions, the longitudinal likelihood, and the priors on the model parameters and random effects. For computation, the log posterior is usually evaluated as a sum of log-likelihood and log-prior terms. The nonlinear survival term must be included whenever a proposed value of \(b_i\), \(\alpha\), or another parameter changes \(m_i(t)\) or the hazard.
Worked Example: Event and Censoring Contributions
Suppose, hypothetically, one subject has constant latent value \(m_i(t)=b_i=1.3\) over follow-up from 0 to 2 time units. Let \(h_0(t)=0.10\) per time unit, \(\alpha=0.40\) per squared biomarker unit, and \(\gamma^\mathsf{T}w_i=0\). First consider an event at time 2.
The exponent is \(\alpha b_i^2=0.40(1.3^2)=0.676\). Thus the event-time hazard is \(0.10\exp(0.676)\approx0.1966\) per time unit, and the cumulative hazard is \(2(0.10)\exp(0.676)\approx0.3932\). The event likelihood contribution is therefore
per time unit, or, on the log scale, \(\log(0.10)+0.676-0.3932\approx-2.020\). If the subject were instead censored at time 2, the contribution would be only \(\exp(-0.3932)\approx0.6750\): the cumulative hazard remains, but there is no event-time hazard factor.
Deriving the Nonlinear Gradients
Gradients are especially important for Hamiltonian Monte Carlo (HMC), which uses derivatives of the log posterior to construct proposals. They are also useful for checking implementations of other samplers. The derivation below holds when the hazard is differentiable in the parameters and the integral can be differentiated under the integral sign; in this smooth, finite-follow-up setting, the integrand and its parameter derivative are assumed integrable.
For compactness, define \(q_i(t)=h_i(t\mid b_i)\). Since \(m_i(t)=x_i(t)^\mathsf{T}\beta+z_i(t)^\mathsf{T}b_i\), its derivative with respect to \(b_i\) is \(z_i(t)\). Applying the chain rule to the log event-time term and to the cumulative hazard yields
The first term is absent under censoring. The second term is not: changing the random effects changes the hazard throughout the observed follow-up interval. Similarly, differentiating with respect to \(\alpha\) gives
These are survival-likelihood gradients only. For the full posterior gradient, add the derivatives of the longitudinal log likelihood and the log prior. For example, if \(b_i\sim N(0,D)\), its log-prior gradient is \(-D^{-1}b_i\). The longitudinal contribution depends on its specified observation model.
Worked Example: Checking the Random-Effects Score
Continue with the constant-trajectory event example, with \(b_i=1.3\), \(\alpha=0.40\), \(h_0=0.10\), and follow-up time 2. Because \(m_i(t)=b_i\), the event contribution to the derivative is \(2\alpha b_i=2(0.40)(1.30)=1.040\). The derivative of the cumulative hazard is
Therefore the survival log-likelihood derivative is \(1.040-0.4089\approx0.6311\). The positive score means that, at this value of \(b_i\), a small increase in \(b_i\) increases this subject's event log likelihood locally; it does not by itself imply that the posterior favors larger \(b_i\).
For an explicit full-posterior check, suppose the hypothetical subject also has one measurement \(y=1.55\) with \(Y\mid b_i\sim N(b_i,0.10)\), and prior \(b_i\sim N(0,13/12)\). The longitudinal score is \((y-b_i)/0.10=(1.55-1.30)/0.10=2.50\), and the prior score is \(-b_i/(13/12)=-1.20\). Thus the full log-posterior derivative with respect to \(b_i\) is approximately \(2.50+0.6311-1.20=1.9311\). Each component has been included once, with the prior and longitudinal terms kept distinct from the survival score.
Time Integration and Numerical Implementation
With a time-varying trajectory, the cumulative hazard will generally require numerical integration. The same quadrature rule should be applied to the cumulative hazard and its derivative. For instance, a Simpson approximation on an interval \([0,2]\), using nodes 0, 1, and 2, approximates the integral of a smooth function \(g\) by \(\{g(0)+4g(1)+g(2)\}/3\). This approximation is not exact in general; it should be refined or compared with a more accurate calculation when the integrand changes rapidly.
Worked Example: Quadrature for a Changing Trajectory
Consider a hypothetical trajectory \(m_i(t)=0.5+0.2t\) on \(0\leq t\leq2\), with \(h_0=0.08\) per time unit, \(\alpha=0.30\), no survival covariates, and an event at time 2. The trajectory values at \(t=0,1,2\) are \(0.5,0.7,0.9\). The corresponding hazard integrand values are
One-panel Simpson quadrature gives a cumulative hazard of \(\{0.08623+4(0.09267)+0.1020\}/3\approx0.1863\). At the event time, \(h_i(2)\approx0.1020\) per time unit, so the approximate log survival contribution is \(\log(0.1020)-0.1863\approx-2.469\).
For the slope \(b_1=0.2\) in \(m_i(t)=b_0+b_1t\), the derivative of the event exponent is \(2\alpha m_i(2)\,2=1.080\). The cumulative-hazard derivative integrand is \(g(t)\,2\alpha m_i(t)t\), which is approximately \(0\), \(0.03892\), and \(0.1102\) at the three nodes. Simpson quadrature gives \(\{0+4(0.03892)+0.1102\}/3\approx0.08862\). The event log-likelihood slope score is therefore approximately \(1.080-0.08862=0.9914\). Refining the quadrature grid provides a direct check on both the likelihood and its gradient.
Sampling Strategy, Comparisons, and Diagnostics
For HMC, evaluate the log posterior and gradient at each proposed state, including the nonlinear event-time term and the integrated-hazard term. A practical implementation computes \(m_i(t)\) at the event time and quadrature nodes, then reuses those values to evaluate both the hazard and its derivatives. If gradients are unavailable or unreliable, a Metropolis update can propose new values and accept or reject them using the ratio of posterior densities; it still requires accurate evaluation of the nonlinear cumulative hazard, but not an analytic gradient.
A linear current-value association replaces \(m_i(t)^2\) with \(m_i(t)\). Its gradient is simpler, but it encodes a different relationship and should not be substituted merely to make computation easier. A nonlinear function can capture curvature or magnitude-based effects that a linear term cannot. Conversely, a flexible function of the latent trajectory may be weakly identified when event information is sparse or the observed trajectory range is narrow. Model choice should follow scientific meaning and data support, not computational convenience alone.
| Approach | What enters the hazard | Computational implication |
|---|---|---|
| Linear current value | \(m_i(t)\) | Simple chain rule; different association shape |
| Squared current value | \(m_i(t)^2\) | Gradient depends on \(2m_i(t)\); cumulative hazard often needs quadrature |
| Metropolis update | Any evaluable likelihood | No gradient required, but posterior density must still be computed correctly |
| HMC update | Differentiable likelihood | Uses gradients, so derivative and integration errors can distort proposals |
Useful implementation checks include comparing analytic or automatic gradients with finite differences at several parameter values, checking that the cumulative hazard is nonnegative, and increasing the quadrature resolution to see whether the log likelihood and gradient stabilize. Check event and censored contributions separately. In particular, a censored subject must still contribute the negative cumulative hazard to the log likelihood and its derivative. A sharp increase in \(m_i(t)^2\) can make the hazard integrand vary quickly; a coarse grid may then underestimate the cumulative hazard and distort the posterior.
A common mistake is to differentiate only the event-time hazard and omit the derivative of the cumulative hazard, or to multiply the event-time term by \(1-\delta_i\) rather than \(\delta_i\). The correction is to start from \(\delta_i\log h_i(T_i)-\int_0^{T_i}h_i(t)\,dt\): the event score is present only when \(\delta_i=1\), while the integral and its derivative are present for both events and censoring. Another pitfall is assuming that a positive \(\alpha\) means higher biomarker values always raise the hazard; for a squared association, the effect depends on the value and reference point of \(m_i(t)\).
Nonlinear terms also have limitations. Squaring can amplify a few extreme latent values, create strong posterior dependence between trajectory and association parameters, and make the hazard highly sensitive to scaling. Centering and scaling the biomarker may improve interpretability and numerical stability, but the transformed units and corresponding prior must be handled consistently. These considerations do not replace convergence assessment; they help identify whether the implemented target is numerically credible.
Check Your Understanding
Answer each question, then compare with the concise solutions below.
- For a censored subject, which terms remain in the log survival likelihood?
- If \(m_i(t)=x_i(t)^\mathsf{T}\beta+z_i(t)^\mathsf{T}b_i\), what is the derivative of the squared association exponent \(\alpha m_i(t)^2\) with respect to \(b_i\)?
- For a constant trajectory \(b_i=1.3\), \(\alpha=0.40\), and cumulative hazard \(H_i=0.3932\), calculate the event survival score with respect to \(b_i\), to four significant figures.
- Name two checks that can reveal an error in a numerical implementation of the nonlinear term.
Solutions. (1) The negative cumulative hazard remains; the event-time log hazard is omitted. (2) The derivative is \(2\alpha m_i(t)z_i(t)\). (3) The score is \(2\alpha b_i(1-H_i)=1.04(1-0.3932)\approx0.6311\). (4) Compare gradients with finite differences and refine the quadrature grid to check stabilization; also verify that cumulative hazards are nonnegative and that censored records retain the integral contribution.