Why use a spline for a transition covariate?
A continuous covariate need not have a straight-line association with a transition hazard. For example, a biomarker might have little association with the hazard at low values, a stronger association in the middle of its range, and a weaker association at high values. A linear term forces one constant change in log hazard for every one-unit increase. A restricted cubic spline allows curvature while retaining a controlled, linear form beyond its boundary knots.
The target here is a hazard ratio comparing two values of a continuous covariate for a specified transition. It is not a comparison of transition probabilities: a hazard ratio describes the relative instantaneous transition rates among individuals at risk for that transition, conditional on the model covariates. The baseline hazard and risk-set definitions are as in transition-specific Cox regression.
Model and spline basis
Consider one transition \(r\to s\), with continuous covariate \(x\) and other covariates \(z\). A proportional-hazards model with an RCS term is
Here \(\lambda_{0,rs}(t)\) is the transition-specific baseline hazard, \(K\) is the number of ordered knots \(\kappa_1<\cdots<\kappa_K\), and \(d_j(x)\) are nonlinear basis functions. The \(K-2\) nonlinear terms accompany the linear term; the spline covariate therefore uses \(K-1\) regression degrees of freedom. Other covariates are held fixed when forming the contrast below.
One common truncated-power definition, for \(j=1,\ldots,K-2\), is
The denominator is a scaling convention: changing the scale of a basis function changes its coefficient but not the fitted curve, provided the model is refitted consistently. Software may use a different, equivalent basis, so coefficient values from different parameterizations need not match. What matters for interpretation is the fitted covariate contribution and its contrast.
The usual model assumptions include proportional hazards for the specified transition, an appropriate conditional covariate adjustment, and a covariate curve adequately represented by the chosen spline. The Cox partial-likelihood analysis also relies on the usual independent-subject and non-informative censoring assumptions, conditional on modeled information. Knots and the covariate’s scaling must be defined consistently when evaluating the fitted model. A spline does not repair a violation of proportional hazards, an unsuitable risk-set definition, or informative loss to follow-up.
From spline coefficients to a hazard ratio
Let \(f_{rs}(x)=\beta_{rs}x+\sum_j\gamma_{rs,j}d_j(x)\) denote the spline contribution. At fixed \(z\), compare covariate values \(x_a\) and \(x_b\) at the same time \(t\). The baseline hazard and the other covariate contribution cancel:
This subtraction is the key interpretive step. Once the curve is nonlinear, \(\beta_{rs}\) alone is not the hazard ratio per unit increase throughout the covariate range. Instead, the local slope of the log hazard at \(x\), where it exists, is \(f'_{rs}(x)\); a finite contrast uses the difference in the entire spline contribution. The ratio is conditional on the other modeled covariates and compares instantaneous hazards for the specified transition.
Worked Example: Building a Three-Knot Spline and Calculating a Contrast
Suppose age is expressed as \(z=(\text{age}-50)/10\), so one unit is ten years. For a hypothetical transition, choose knots at \(z=-1,0,1\), corresponding to ages 40, 50, and 60. With three knots, one nonlinear basis function is
Assume the fitted contribution is \(f(z)=0.30z-0.04d(z)\), with all other covariates held equal. To compare age 55 with age 45, the corresponding values are \(z_b=0.5\) and \(z_a=-0.5\). At \(z=-0.5\), \(d(-0.5)=0.5^3=0.125\). At \(z=0.5\), \(d(0.5)=1.5^3-2(0.5)^3=3.375-0.250=3.125\). Therefore,
Under this fitted model, the instantaneous hazard of the specified transition at age 55 is estimated to be 1.197 times the hazard at age 45, or about 19.7% higher, conditional on the other covariates. The contrast is for a ten-year age difference at these particular values; it should not be presented as a constant effect for every ten-year increase.
Uncertainty for a chosen contrast
A hazard-ratio contrast is a linear combination of fitted coefficients on the log scale. Let \(\widehat{\boldsymbol\eta}\) collect the spline coefficients, and let \(\mathbf c\) contain the corresponding basis differences between \(x_b\) and \(x_a\). Then \(\widehat{\ell}=\mathbf c^{\mathsf T}\widehat{\boldsymbol\eta}\) estimates the log hazard ratio. If \(\widehat V\) is the estimated covariance matrix of those coefficients, its Wald standard error is
A 95% Wald confidence interval for the hazard ratio is obtained by first forming \(\widehat{\ell}\pm1.96SE(\widehat{\ell})\), then exponentiating both endpoints. The interval is not a range of covariate values and is not a 95% probability statement about the fixed true hazard ratio. Its coverage interpretation is frequentist: intervals constructed this way over repeated samples would contain the true contrast about 95% of the time under the model and approximation.
Worked Example: A Confidence Interval for the Spline Contrast
Continue the hypothetical model in the preceding example. Suppose the coefficient estimates are \(\hat\beta=0.30\) and \(\hat\gamma=-0.04\), with estimated variances \(0.0100\) and \(0.000400\), and covariance \(-0.00100\). For the 55-versus-45 contrast, the coefficient vector is \(\mathbf c=(1,3)^{\mathsf T}\), because the linear-basis difference is 1 and the nonlinear-basis difference is 3. Thus,
The estimated log hazard ratio is \(0.180\). Its 95% Wald interval is \(0.180\pm1.96(0.08718)\), or approximately \((0.0091,0.3509)\). Exponentiating gives a hazard-ratio interval of \((e^{0.0091},e^{0.3509})=(1.009,1.420)\). The estimated hazard is higher at age 55; this interval is compatible with effects ranging from about 0.9% to 42.0% higher, conditional on the model covariates. The interval just excludes 1, which corresponds to a log contrast of zero.
Choosing complexity and checking the fit
Knots are commonly placed at selected quantiles of the covariate distribution, with the number and locations chosen before examining the desired result where practical. Their placement should also reflect scientific context and where data support exists. More knots permit more curvature but require more information to estimate reliably. With \(K\) knots, the nonlinear component has \(K-2\) degrees of freedom; a test of linearity compares the nonlinear terms jointly with zero, not each coefficient in isolation.
For example, in a three-knot model there is one nonlinear coefficient. Comparing that model with the linear-only model is a one-degree-of-freedom nested test if both use the same data, covariates, and transition risk sets and the knots were fixed. For more knots, a joint test uses \(K-2\) degrees of freedom. A failure to reject linearity does not prove the curve is linear, particularly when the data are sparse; conversely, a detected curvature need not imply a large or clinically important contrast.
Inspect the estimated curve and confidence bands over the observed covariate range, along with the covariate distribution and transition-specific risk-set support. A curve that bends sharply where few individuals or events contribute is unstable. The restricted tails are linear, not flat: beyond the boundary knots, the fitted log hazard continues linearly. This is often more stable than unconstrained cubic extrapolation, but it does not make extrapolation reliable. Avoid substantive conclusions at covariate values far outside observed support.
Worked Example: Testing Whether Curvature Improves Fit
Suppose, hypothetically, a linear model and a three-knot spline model are fitted to the same transition data, with identical adjustment terms and the same risk sets. Their maximized partial log-likelihoods are \(-412.6\) for the linear model and \(-410.9\) for the spline model. The models are nested, and the spline adds one nonlinear coefficient. The likelihood-ratio statistic is
Under the null of no nonlinear contribution and the usual large-sample approximation, this is compared with a chi-square distribution with 1 degree of freedom. The two-sided upper-tail p-value is about 0.065. At \(\alpha=0.05\), these hypothetical data do not provide sufficient evidence to reject the linear form in favor of this spline. This does not establish exact linearity; it says that the observed improvement is not statistically significant at that threshold under the stated comparison.
Derivation of the restricted linear tails
The tail restriction in the basis can be checked directly. For \(x\geq\kappa_K\), all three positive-part terms in \(d_j(x)\) are ordinary cubes. Write \(A=(\kappa_K-\kappa_j)/(\kappa_K-\kappa_{K-1})\) and \(B=(\kappa_{K-1}-\kappa_j)/(\kappa_K-\kappa_{K-1})\). The coefficient of \(x^3\) in the numerator is \(1-A+B=0\). The coefficient of \(x^2\) is proportional to \[ \kappa_j-A\kappa_{K-1}+B\kappa_K=0. \] These equalities follow by substituting \(A\) and \(B\) and collecting terms. The cubic and quadratic terms therefore cancel, leaving a function at most linear in \(x\) above the highest knot. Below \(\kappa_1\), every positive-part term is zero, so the nonlinear basis contribution is zero there and the full covariate contribution is linear. Thus the model is linear in both tails by construction.
Alternatives, limitations, and common mistakes
A linear covariate term is simpler and more precise when the log-hazard relationship is adequately linear, but it can misrepresent curvature. Categorizing a continuous covariate avoids specifying a smooth curve, but discards within-category information and makes results depend on arbitrary cut points. An RCS offers a flexible, smooth middle-range shape while constraining tails; it still imposes a particular functional form and cannot guarantee that the true association is captured.
- Wrong: “The spline coefficient is the hazard ratio per unit increase.” Correction: coefficients multiply basis functions; compute the basis difference for the two covariate values and exponentiate the resulting log contrast.
- Wrong: “The restricted tail is constant.” Correction: the tail is linear on the log-hazard scale, so the hazard can continue to change beyond the outer knot.
- Wrong: “A nonsignificant curvature test proves the effect is linear.” Correction: it indicates insufficient evidence against linearity for that test and sample; limited event information can make curvature difficult to detect.
- Wrong: “A flexible spline removes the proportional-hazards assumption.” Correction: the spline flexes the covariate association, while proportional hazards still requires that this association does not change with time.
A practical result should report the transition, covariate scale, knot specification, comparison values, hazard ratio and interval, and the range of data support. When many knots, knot locations, or contrasts are selected after examining results, ordinary confidence intervals and p-values may not reflect that selection. Interpret the curve as a conditional association, not as evidence that changing the covariate would cause the hazard to change.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- With \(K=5\) knots, how many nonlinear spline basis terms and how many total regression degrees of freedom are used for the covariate?
- A fitted model has \(f(x)=0.2x+0.1d(x)\). At two values, \(x_a=2\), \(x_b=5\), \(d(x_a)=1\), and \(d(x_b)=4\). Calculate the log hazard ratio and hazard ratio for \(x_b\) versus \(x_a\).
- Why does an RCS model not justify extrapolating far beyond the observed covariate range?
- A three-knot spline is compared with a linear model using a likelihood-ratio statistic of 5.02. What degrees of freedom apply to the usual test, and what aspect of the model is being tested?
Solutions. (1) There are \(K-2=3\) nonlinear terms and \(K-1=4\) total regression degrees of freedom including the linear term. (2) The log contrast is \(0.2(5-2)+0.1(4-1)=0.6+0.3=0.9\); the hazard ratio is \(e^{0.9}=2.460\). (3) The tails are constrained to be linear, but that restriction does not supply data support or guarantee that the real association continues linearly outside the observed range. (4) The test has 1 degree of freedom because the three-knot model adds one nonlinear term; it tests whether that nonlinear contribution improves fit beyond the linear covariate effect, not whether the entire covariate association is zero.