Tutorials › Nonlinear Mixed-Effects Models (NLME) › Piecewise Linear Covariate Effects with Prespecified Knots

Functional Forms for Covariates · Tutorial 495 of 797

Piecewise Linear Covariate Effects with Prespecified Knots

Build and interpret continuous, two-segment covariate relationships using a prespecified knot, including the segment slopes and the effect of choosing a reference value above the knot.

Intermediate 12 min read

What You'll Learn

  • Define a hinge term and use it to construct a continuous piecewise linear covariate effect.
  • Calculate and interpret the slopes below and above a prespecified knot.
  • Anchor the relationship at a reference value, including when that value lies above the knot.
  • Interpret piecewise effects on additive and log parameter scales.
  • Diagnose weak support for a knot and distinguish a slope change from a discontinuity.
  • Compare piecewise linear effects with a single linear or quadratic effect.

Why Use a Prespecified Knot?

A single linear covariate effect assumes the same rate of change across the entire observed covariate range. That can be too restrictive when a parameter is expected to change at one rate below a clinically meaningful value and another rate above it. A piecewise linear function allows those rates to differ while keeping the relationship continuous: the parameter does not jump at the knot.

In an NLME model, this function describes how a population parameter’s typical value depends on a covariate. It can be used on an additive parameter scale, or on a transformed scale such as the log scale for a positive parameter. The knot is a specified covariate value, not an estimated change-point in the formulation developed here.

Definition: For covariate \(x\) and prespecified knot \(k\), the hinge term is \((x-k)_+=\max(x-k,0)\). It is zero at and below the knot and increases linearly with \(x\) above the knot. A continuous piecewise linear function combines a linear term in \(x\) with a coefficient multiplying this hinge.

Model Form and Segment Slopes

Let \(\theta_{\mathrm{pop}}(x)\) denote the typical population value of a parameter at covariate value \(x\). Choose a reference value \(x_{\mathrm{ref}}\), at which the typical value is \(\theta_{\mathrm{ref}}\). An additive-scale parameterization that is correctly anchored for any reference value is

$$ \theta_{\mathrm{pop}}(x) = \theta_{\mathrm{ref}} +b_1(x-x_{\mathrm{ref}}) +b_2\left[(x-k)_+-(x_{\mathrm{ref}}-k)_+\right]. $$

Here \(b_1\) is the slope below the knot, and \(b_2\) is the change in slope at the knot. Thus, the slope above the knot is \(b_1+b_2\). The coefficients have units of parameter units per covariate unit. For example, if \(\theta\) is clearance in L/h and \(x\) is weight in kg, each slope is in (L/h)/kg.

Subtracting the hinge value at \(x_{\mathrm{ref}}\) ensures that substituting \(x=x_{\mathrm{ref}}\) returns \(\theta_{\mathrm{ref}}\), including when the reference value is above the knot. The expression can be written as two ordinary linear segments:

$$ \theta_{\mathrm{pop}}(x)= \begin{cases} \theta_{\mathrm{ref}}+b_1(x-x_{\mathrm{ref}})-b_2(x_{\mathrm{ref}}-k)_+, & x\leq k,\\ \theta_{\mathrm{ref}}+b_1(x-x_{\mathrm{ref}})+b_2\left[(x-k)-(x_{\mathrm{ref}}-k)_+\right], & x>k. \end{cases} $$

The function is continuous at \(k\): the hinge is zero at the knot, and its value approaches zero from above as \(x\) approaches \(k\). The derivative, where it exists, is \(b_1\) below \(k\) and \(b_1+b_2\) above \(k\). If \(b_2\ne 0\), the slope changes at \(k\), so the function generally has a corner there, not a jump.

How the Hinge Produces a Slope Change

The slope statements follow directly from the definition of the hinge. Below the knot, \((x-k)_+=0\), so changing \(x\) changes only the term with coefficient \(b_1\). Above the knot, \((x-k)_+=x-k\), so the two terms involving \(x\) contribute together.

$$ x\leq k:\quad \frac{d\theta_{\mathrm{pop}}}{dx}=b_1, \qquad x>k:\quad \frac{d\theta_{\mathrm{pop}}}{dx}=b_1+b_2. $$

At the knot itself, the left and right derivatives need not agree. The function still has a well-defined value there, and both segments meet at that value. A negative \(b_2\) means the slope decreases across the knot; it does not necessarily mean that the upper segment slopes downward. The upper segment increases whenever \(b_1+b_2>0\).

For a positive parameter, the same construction can be made on the log scale:

$$ \log\theta_{\mathrm{pop}}(x) = \log\theta_{\mathrm{ref}} +b_1(x-x_{\mathrm{ref}}) +b_2\left[(x-k)_+-(x_{\mathrm{ref}}-k)_+\right]. $$

In this form, \(b_1\) and \(b_1+b_2\) are slopes of log parameter per covariate unit. A change of \(\Delta x\) wholly within one segment multiplies the typical parameter by \(\exp(b\Delta x)\), with \(b\) the slope for that segment. This log-scale form keeps the typical parameter positive. It is not the same as an additive change in the parameter itself.

In a typical NLME specification, an individual parameter may be written as \(\theta_i=\theta_{\mathrm{pop}}(x_i)\exp(\eta_i)\), where \(\eta_i\) is an individual random effect. The covariate function specifies the typical value at \(\eta_i=0\); it does not by itself specify the marginal mean across individuals. For example, variability in \(\eta_i\) can make the mean of \(\exp(\eta_i)\) differ from one even when \(\eta_i\) has mean zero.

Worked Example: A Negative Slope Change with an Increasing Relationship Above the Knot

Suppose a hypothetical additive model describes typical clearance in L/h as a function of age in years. Let \(x_{\mathrm{ref}}=50\), \(k=65\), \(\theta_{\mathrm{ref}}=8.00\) L/h, \(b_1=0.0300\) (L/h)/year, and \(b_2=-0.0200\) (L/h)/year. Calculate the slopes and typical clearance at age 75.

Below age 65, the slope is \(b_1=0.0300\) (L/h)/year. Above age 65, it is \(b_1+b_2=0.0300-0.0200=0.0100\) (L/h)/year. The slope decreases, but the upper-segment slope remains positive, so typical clearance still increases with age above the knot.

Since the reference value is below the knot, its hinge is zero. At age 75, the hinge is \(75-65=10\) years. Substitution gives

$$ \theta_{\mathrm{pop}}(75) =8.00+0.0300(75-50)-0.0200(10) =8.00+0.750-0.200 =8.55\ \mathrm{L/h}. $$

The units are consistent: each slope multiplied by a difference in years gives L/h. The result is 0.55 L/h above the reference value. That increase comprises 0.450 L/h over the first 15 years, from age 50 to 65, and 0.100 L/h over the next 10 years, from age 65 to 75.

Worked Example: A Log-Scale Effect Across the Knot

Consider a hypothetical positive parameter with a log-scale covariate effect. Let \(x\) be age in years, \(x_{\mathrm{ref}}=50\), \(k=65\), \(\theta_{\mathrm{ref}}=8.00\) L/h, \(b_1=0.0150\) per year, and \(b_2=0.0300\) per year. Find the typical value at age 75 and interpret the segment slopes.

The log-scale slope below the knot is \(0.0150\) per year; above it, the slope is \(0.0150+0.0300=0.0450\) per year. From age 50 to 75, the first 15 years are below the knot and the final 10 are above it. The change in log typical value is therefore

$$ 0.0150(65-50)+0.0450(75-65) =0.225+0.450 =0.675. $$

Equivalently, the anchored hinge formula gives \(0.0150(75-50)+0.0300(75-65)=0.675\). Thus

$$ \theta_{\mathrm{pop}}(75) =8.00\exp(0.675) \approx 15.71\ \mathrm{L/h}. $$

This is a typical value about \(15.71/8.00\approx1.964\) times the typical value at age 50, or about 96.4% higher. The coefficients are log-scale slopes, not additive changes in L/h per year. This is a model-based contrast between typical values, not evidence that changing an individual’s age causes clearance to change.

Worked Example: Anchoring Above the Knot

Suppose an additive model has \(\theta_{\mathrm{ref}}=10.00\) mg/L, \(x_{\mathrm{ref}}=75\) mg/L, \(k=65\) mg/L, \(b_1=0.0200\), and \(b_2=-0.00500\) in parameter units per covariate unit. Verify the reference value and calculate the typical parameter at \(x=60\) and \(x=80\).

The hinge at the reference is \((75-65)_+=10\), so the anchored hinge difference is zero when \(x=75\). The model returns exactly \(\theta_{\mathrm{pop}}(75)=10.00\) mg/L.

At \(x=60\), the hinge is zero. Substitution, including the reference hinge, gives

$$ \theta_{\mathrm{pop}}(60) =10.00+0.0200(60-75)-0.00500[0-10] =10.00-0.300+0.050 =9.750\ \mathrm{mg/L}. $$

At \(x=80\), the hinge is \(80-65=15\). Therefore,

$$ \theta_{\mathrm{pop}}(80) =10.00+0.0200(80-75)-0.00500[15-10] =10.00+0.100-0.025 =10.075\ \mathrm{mg/L}. $$

The slope below the knot is \(0.0200\); above it, the slope is \(0.0200-0.00500=0.0150\). The results are consistent: moving from 75 to 80 increases the value by \(0.0150(5)=0.0750\) mg/L. This example shows why omitting the reference hinge correction is wrong when the reference lies above the knot.

Assumptions, Diagnostics, and Alternatives

The function is appropriate when a continuous relationship with two approximately linear segments is a scientifically defensible description on the chosen parameter scale. Its knot should be prespecified, for example from a mechanistic consideration, a clinical convention, or a design-based decision made before examining the outcome pattern. The covariate must be measured on a scale for which those linear slopes have a meaningful interpretation. A log-scale model additionally requires a positive parameter and a meaningful log-scale effect.

The data need useful covariate information on both sides of the knot. If there are few observations or little range on one side, the corresponding slope may be weakly informed and sensitive to a few subjects. In NLME data, the effective information also depends on the number and distribution of individuals, not simply the number of repeated measurements. Examine the covariate distribution around and on both sides of the knot, uncertainty in the slope estimates, and whether fitted values and residual diagnostics show systematic patterns. A sparse region around the knot may leave the estimated change in slope especially uncertain.

The hinge term adds one slope-change coefficient relative to a single linear term. Because the knot is fixed, fitting this model does not search over possible knot locations. If the knot is instead chosen by scanning the data for the best fit, ordinary inference that treats that selected knot as fixed does not account for the search. A fitted curve should also be checked for implausible predictions, particularly when extrapolated beyond the observed covariate range.

A single linear effect is simpler but cannot represent a slope change. A quadratic effect, covered in the earlier material on quadratic covariate effects, changes slope gradually and can curve throughout the range; a hinge model instead has constant slopes within segments and a specified location for the change. A piecewise model is therefore useful when a change in rate at a particular value is plausible, but it is not automatically better merely because it fits the observed data more closely. More flexible approaches, including restricted cubic splines, are distinct alternatives and should not be treated as interchangeable with a single prespecified hinge.

Model formWhat it allowsMain consideration
Single linear termOne constant slopeSimple, but cannot represent a slope change
Prespecified hingeTwo constant slopes meeting continuously at a fixed knotInterpretable change in slope; support is needed on both sides
Quadratic effectA smoothly changing slope over the rangeCurvature is not localized to a knot and can behave poorly when extrapolated
Restricted cubic splineA more flexible smooth relationshipGreater flexibility and additional modeling choices

Common Mistakes and Practical Checks

  • Calling \(b_2\) the upper slope. It is the change in slope. The upper slope is \(b_1+b_2\).
  • Assuming a negative slope change means the upper segment decreases. Check the sum \(b_1+b_2\); it can remain positive.
  • Using an unanchored hinge with a reference above the knot. The term \((x-k)_+\) is then nonzero at the reference. Subtract its reference value to preserve \(\theta_{\mathrm{ref}}\).
  • Describing a kink as a jump. The hinge model is continuous at the knot; its derivative can change there.
  • Interpreting a log-scale coefficient as an additive parameter change. It describes change in log parameter; exponentiation gives a multiplicative contrast.
  • Trusting extrapolation or a poorly supported slope. Check the covariate coverage and uncertainty on both sides before interpreting segment-specific estimates.
Key takeaway: In a continuous two-segment hinge model, the lower slope is \(b_1\), the upper slope is \(b_1+b_2\), and \(b_2\) is the slope change. Use the anchored hinge difference when the reference value may lie above the knot.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. For \(b_1=0.40\) and \(b_2=-0.15\), what are the lower and upper slopes? Is the upper segment increasing or decreasing?
  2. A model has \(x_{\mathrm{ref}}=20\), \(k=10\), and \(b_2=0.3\). Why is \((x-k)_+\) alone not an adequately anchored hinge term?
  3. On a log scale, a within-segment covariate increase of 4 units has slope \(0.02\) per unit. What is the multiplicative change in the typical parameter?
  4. What property of the hinge function ensures continuity at the knot, even if \(b_2\ne0\)?
  5. Give one reason to be cautious about interpreting an estimated slope above a prespecified knot.

Solutions. (1) The lower slope is \(0.40\); the upper slope is \(0.40-0.15=0.25\), so the upper segment is increasing. (2) At the reference, \((20-10)_+=10\), not zero. Use \((x-k)_+-(x_{\mathrm{ref}}-k)_+\) so the hinge contribution vanishes at the reference. (3) The log change is \(0.02(4)=0.08\), giving a multiplicative change of \(\exp(0.08)\approx1.083\), or about an 8.33% increase. (4) The hinge equals zero at the knot and approaches zero from above, so both linear pieces meet at the same value. (5) There may be few individuals or little covariate range above the knot, making that slope uncertain and sensitive to individual observations.