Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Spline Baseline Hazards with Smoothing Priors

Bayesian Joint Models · Tutorial 313 of 697

Spline Baseline Hazards with Smoothing Priors

You will construct a spline baseline hazard, specify a proper smoothing prior for its coefficients, and interpret the role and limitations of its precision.

Advanced 12 min read

What You'll Learn

  • Express a baseline log hazard as a linear combination of fixed spline basis functions.
  • Specify a proper second-difference Gaussian smoothing prior and identify its unpenalized components.
  • Derive the corresponding quadratic roughness penalty in the log posterior.
  • Interpret smoothing precision through coefficient differences and hypothetical hazard calculations.
  • Compare spline baselines with Weibull and piecewise-exponential alternatives.
  • Recognize boundary, knot, scale, and prior-sensitivity limitations.

Why Smooth the Baseline Hazard?

A baseline hazard describes how the event rate changes over time for a subject at the reference covariate and association values. A Weibull baseline imposes a particular global shape; a piecewise-exponential baseline allows changes between intervals but can create abrupt jumps at their boundaries. A spline offers a flexible middle ground: its log hazard is assembled from smooth basis functions, while a prior discourages implausibly rapid changes.

In a Bayesian joint model, this baseline is combined with the longitudinal process and the survival contribution. The spline prior concerns the shape of the baseline log hazard; it does not replace the model for the longitudinal measurements or the association between the longitudinal trajectory and event risk. The key modeling choice is how strongly to regularize changes in the spline coefficients.

Definition: Let \(B_1(t),\ldots,B_K(t)\) be fixed spline basis functions on the modeled time interval, and let \(\gamma_1,\ldots,\gamma_K\) be their coefficients. A spline baseline log hazard is $$ \log h_0(t)=\sum_{k=1}^{K}B_k(t)\gamma_k=\mathbf{B}(t)^\mathsf{T}\boldsymbol{\gamma}, $$ so \(h_0(t)=\exp\{\mathbf{B}(t)^\mathsf{T}\boldsymbol{\gamma}\}\). Here \(\mathbf{B}(t)\) is the vector of basis values and \(\boldsymbol{\gamma}\) is the coefficient vector. Hazard values are expressed in the inverse time unit used for \(t\).

The knots, spline degree, and basis are fixed before fitting or otherwise specified as part of the model. They determine the functions available to describe the curve. The coefficient prior then regulates how the curve uses that flexibility. With a B-spline basis, the basis functions are local: changing one coefficient primarily affects a portion of the time range. The coefficients are not generally log hazards at individual observed times.

The Joint-Model Likelihood Contribution

For clarity, consider a shared-parameter survival model with subject-specific random effects \(b_i\), observed event or censoring time \(T_i\), and event indicator \(\delta_i\), where \(\delta_i=1\) denotes an observed event and \(\delta_i=0\) denotes right censoring. One common conditional hazard is

$$ h_i(t\mid b_i)=h_0(t)\exp\!\left\{\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}+\alpha m_i(t)\right\}. $$

Here \(\mathbf{x}_i\) is a vector of survival covariates, \(\boldsymbol{\beta}\) their coefficients, \(m_i(t)\) the subject-specific longitudinal trajectory evaluated at time \(t\), and \(\alpha\) the association parameter. Conditional on the random effects and model parameters, subject \(i\)'s survival likelihood contribution is

$$ L_{Si}=h_i(T_i\mid b_i)^{\delta_i} \exp\!\left\{-\int_0^{T_i}h_i(u\mid b_i)\,du\right\}. $$

The spline enters both the event hazard and the integrated hazard. For a censored subject, the event-hazard factor is absent, but the survival through \(T_i\) still contributes through the integral. The joint likelihood also includes the longitudinal measurement model, and inference integrates or samples over the random effects as appropriate. This tutorial focuses on the prior that regularizes \(\boldsymbol{\gamma}\).

A Second-Difference Smoothing Prior

A standard choice penalizes second differences of adjacent coefficients. A small second difference means that successive coefficient increments are similar; this tends to favor a gently changing coefficient sequence rather than abrupt curvature. For \(k=3,\ldots,K\), define \(\Delta^2\gamma_k=\gamma_k-2\gamma_{k-1}+\gamma_{k-2}\).

Definition: A second-order Gaussian smoothing prior has $$ \Delta^2\gamma_k\mid\tau\ \sim\ N(0,\tau^{-1}),\qquad k=3,\ldots,K, $$ independently, together with proper priors on \(\gamma_1\) and \(\gamma_2\). The parameter \(\tau>0\) is the smoothing precision. Conditional on the first two coefficients, the prior density for the remaining coefficients is proportional to $$ \exp\!\left\{-\frac{\tau}{2}\sum_{k=3}^{K}(\Delta^2\gamma_k)^2\right\}. $$

The proper priors on the first two coefficients matter. The second-difference terms alone do not penalize a sequence with zero second differences: any sequence \(\gamma_k=a+b(k-1)\) has \(\Delta^2\gamma_k=0\). Thus the second-difference prior by itself is an intrinsic, improper prior on the full coefficient vector. Proper level and slope priors, or an explicitly justified alternative constraint and prior, are needed for a proper specification. A common choice is \(\gamma_1\sim N(m_1,v_1)\) and \(\gamma_2\sim N(m_2,v_2)\), independently, with finite \(v_1,v_2>0\).

A hyperprior can be assigned to \(\tau\), for example a Gamma distribution specified by shape and rate, or \(\tau\) can be fixed. A hyperprior allows the data to inform smoothness, but it does not make the prior irrelevant: its scale and the coefficient units still influence the range of smoothing supported by the model.

Why the Prior Is a Roughness Penalty

The prior's effect can be seen directly by taking its logarithm. Ignoring terms that do not depend on \(\boldsymbol{\gamma}\), the second-difference contribution to the log posterior is

$$ -\frac{\tau}{2}\sum_{k=3}^{K} (\gamma_k-2\gamma_{k-1}+\gamma_{k-2})^2. $$

The survival likelihood rewards coefficient patterns that fit the observed event and censoring times. The prior subtracts a cost for curvature in the coefficient sequence. The posterior therefore balances fit against roughness; it is not obtained by smoothing the data independently of the likelihood.

1
Form the coefficient increments.
Compute \(d_k=\gamma_k-\gamma_{k-1}\) for each adjacent pair.
2
Measure changes in increments.
The second difference is \(d_k-d_{k-1}=\Delta^2\gamma_k\). A zero value means the coefficient sequence is locally linear in its index.
3
Apply the prior penalty.
Each squared second difference adds to the roughness sum, which is multiplied by \(\tau/2\) in the negative log prior.

This is a coefficient-space penalty. It encourages a smooth baseline curve for common spline bases, but it is not exactly the integrated squared second derivative of \(\log h_0(t)\) in every basis or knot configuration. Knot placement, basis scaling, and boundary behavior therefore remain important parts of the specification.

Worked Example: Computing a Baseline Hazard at One Time

Suppose time is measured in months and, at month 6, the fixed spline basis has values \(\mathbf{B}(6)=(0.1,0.6,0.3)\). Take hypothetical coefficients \(\boldsymbol{\gamma}=(-3,-2,-1)\). For a subject with \(\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}=0.2\), \(m_i(6)=0.5\), and \(\alpha=0.4\), calculate the baseline and subject-specific hazard at that time.

The baseline log hazard is $$ \mathbf{B}(6)^\mathsf{T}\boldsymbol{\gamma} =(0.1)(-3)+(0.6)(-2)+(0.3)(-1)=-0.3-1.2-0.3=-1.8. $$

Thus the baseline hazard is \(h_0(6)=\exp(-1.8)=0.1653\) per month. The subject-specific linear predictor added to the baseline is \(0.2+(0.4)(0.5)=0.4\), so $$ h_i(6\mid b_i)=0.1653\exp(0.4)=0.1653(1.4918)=0.2466 $$ per month. This is the instantaneous conditional event rate at month 6 under the stated hypothetical parameter values, not the probability of an event during the month.

Worked Example: Evaluating the Smoothing Penalty

Take four hypothetical coefficients \(\boldsymbol{\gamma}=(-3,-2,-1.5,-1)\). The second differences are \(\Delta^2\gamma_3=-1.5-2(-2)+(-3)=-0.5\) and \(\Delta^2\gamma_4=-1-2(-1.5)+(-2)=0\). The total squared roughness is therefore \(0.5^2+0^2=0.25\).

Ignoring the same normalizing factors and the priors on the first two coefficients, the log-prior penalty is \(-\tau(0.25)/2\). At \(\tau=4\), this is \(-0.5\); at \(\tau=16\), it is \(-2\). Consequently, this coefficient pattern receives less prior weight relative to a zero-second-difference pattern when the precision is larger. The comparison concerns the curvature penalty only; the full prior density also depends on its normalization and on the proper priors for the initial coefficients.

For an individual second difference, the prior standard deviation is \(\tau^{-1/2}\). It is \(0.5\) at \(\tau=4\) and \(0.25\) at \(\tau=16\). Under the stated normal prior, the probabilities that its absolute value is below \(0.5\) are approximately \(0.683\) and \(0.954\), respectively. These are prior probabilities for a coefficient difference, not posterior probabilities for a particular fitted curve.

Worked Example: Event Contribution Under the Spline Hazard

Continue with the hypothetical subject-specific hazard \(h_i(6\mid b_i)=0.2466\) per month. Suppose the subject has an observed event at month 6 and, after integrating the fitted hazard over months 0 through 6, the cumulative hazard is \(0.80\). The survival likelihood contribution is $$ L_{Si}=h_i(6\mid b_i)\exp(-0.80) =(0.2466)(0.4493)=0.1108 $$ per month.

The density contribution has inverse-month units because an event time is continuous; the survival probability \(\exp(-0.80)=0.4493\) is dimensionless. The cumulative hazard value \(0.80\) is hypothetical and is not obtained from the single hazard value at month 6: it requires integrating the subject-specific hazard over the whole interval. If the observation were right-censored at month 6, its contribution would instead be \(\exp(-0.80)\), with no factor \(h_i(6\mid b_i)\).

Interpreting Precision and Checking the Fit

Increasing \(\tau\) narrows the prior distribution of each second difference and increases the roughness penalty. In the limit of very large \(\tau\), the coefficients are driven toward a linear sequence in their index, subject to the likelihood and the remaining priors. At finite \(\tau\), the posterior reflects both the likelihood and the smoothing prior. It is accurate to say that higher precision favors smoother coefficient sequences; it is not generally correct to promise that every posterior feature of the hazard curve changes monotonically as \(\tau\) increases.

Useful checks include plotting posterior baseline hazard curves over the observed follow-up range, inspecting behavior near boundaries, and comparing prior and posterior draws of the curve. These checks can reveal implausible oscillations, near-flat curves imposed by excessive smoothing, or unstable behavior where event information is limited. Check that the time units and knot locations are sensible, and examine whether the implied hazards and cumulative hazards are plausible across the follow-up interval. A prior predictive check can help show what curve shapes the chosen coefficient priors and precision make plausible before conditioning on the observed data.

A key limitation is that \(\tau\) is not directly comparable across arbitrary basis choices. Changing the number or spacing of knots, the spline degree, or coefficient scaling can change how coefficient differences correspond to curve roughness. Boundary behavior is another concern: there may be less information near the ends of follow-up, and the spline's edge shape can be sensitive to the basis and prior. Report the basis, knot specification, and prior on both the smoothing precision and the unpenalized components.

How This Baseline Compares with Alternatives

Baseline approachShape flexibilityMain trade-off
Weibull baselineOne global parametric shapeCompact and interpretable, but can be too restrictive if the time pattern differs from the Weibull form.
Piecewise-exponential baselineSeparate constant hazards over specified intervalsFlexible across intervals, but the hazard can jump at cut points and results depend on interval choices.
Spline with smoothing priorFlexible, smoothly varying log hazardCan represent gradual shape changes, but requires choices about basis, knots, and smoothing prior.

These are alternatives for representing \(h_0(t)\), not alternatives to specifying the longitudinal-survival association. A spline prior also cannot create event-time information that the data do not contain: where observations provide little information, the posterior curve may remain strongly influenced by its prior and basis.

Common Mistakes

  • Confusing precision with variance. The second-difference variance is \(\tau^{-1}\), so larger \(\tau\) means stronger smoothing, not weaker smoothing.
  • Using only second-difference terms and calling the prior proper. Linear coefficient sequences have zero penalty. Specify proper priors for the level and slope, or a justified alternative that makes the full prior proper.
  • Interpreting coefficients as hazard values. A coefficient is a weight on a basis function; the log hazard at time \(t\) is the weighted sum of all basis values at \(t\).
  • Treating a hazard as an event probability. A hazard is an instantaneous rate. Event probabilities over intervals depend on the cumulative hazard over those intervals.
  • Assuming a large number of knots guarantees a good fit. More basis functions increase flexibility and can make regularization and prior sensitivity more consequential.
Key takeaway: A spline baseline writes the log hazard as a basis expansion. A second-difference Gaussian prior penalizes coefficient curvature, with precision \(\tau\) controlling the strength of that prior preference. The resulting posterior curve depends jointly on the event likelihood, the basis and knots, and proper priors for both curvature and the unpenalized coefficient components.

Check Your Understanding

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

  1. If \(\tau\) increases from 9 to 25, what happens to the prior standard deviation of a second difference?
  2. Why are proper priors or constraints needed beyond a second-difference penalty?
  3. For coefficients \((-2,-1,-1)\), calculate the second differences and the total squared roughness.
  4. Why does a right-censored subject still contribute information about the spline baseline?

Solutions. (1) The standard deviation changes from \(1/\sqrt{9}=1/3\) to \(1/\sqrt{25}=1/5\), so the prior concentrates more strongly near zero second differences. (2) Any coefficient sequence linear in its index has all second differences equal to zero; the penalty does not control its level or slope, so the full coefficient prior would otherwise be improper. (3) There is one second difference: \(-1-2(-1)+(-2)=-1\), so the total squared roughness is \(1\). (4) Censoring establishes that the subject remained event-free through the censoring time, contributing the survival term \(\exp\{-\int_0^{T_i}h_i(u\mid b_i)\,du\}\), which depends on the baseline curve over that interval.

Clinical Biostats