Tutorials › Regression Analysis (Undergraduate) › Choosing Knot Locations for Regression Splines

Piecewise Regression and Splines · Tutorial 449 of 991

Choosing Knot Locations for Regression Splines

Compare substantive, evenly spaced, and predictor-quantile knot choices, and learn to check whether the resulting segments are adequately supported by the observed predictor values.

Advanced 11 min read

What You'll Learn

  • Describe the fixed-knot piecewise linear regression model and how knots allocate changes in slope.
  • Choose knots using meaningful domain thresholds when they are justified.
  • Calculate evenly spaced knots across a predictor range.
  • Locate predictor-quantile knots and check the resulting segment counts.
  • Explain why balanced counts do not guarantee balanced predictor coverage.
  • Diagnose when sparse regions make local flexibility poorly supported.

Why Knot Location Matters

In piecewise linear regression, a knot is a predictor value where the fitted line is allowed to change slope. Choosing how many knots to use determines how many slope changes the model can represent; choosing where to put them determines where that flexibility is available. A knot in a region with many observations may be informed by substantial local data, while a knot near a long gap may create a slope change that the data can scarcely distinguish.

There is no single knot-placement rule that works best for every problem. Substantive knowledge can identify meaningful thresholds, evenly spaced knots distribute them across the predictor range, and predictor-quantile knots seek to distribute observations across segments. These strategies answer different practical needs, and all require checking the actual support in the data.

The Fixed-Knot Model

For observations \((x_i,y_i)\), a continuous piecewise linear model with \(m\) fixed knots \(k_1<\cdots<k_m\) can be written using the hinge function \((x-k)_+=\max(0,x-k)\):

$$ Y_i=\beta_0+\beta_1x_i+\sum_{j=1}^{m}\gamma_j(x_i-k_j)_++\varepsilon_i $$

Here, \(\beta_0\) is the intercept, \(\beta_1\) is the slope before the first knot, and \(\gamma_j\) is the change in slope at knot \(k_j\). Thus, the slope between \(k_j\) and \(k_{j+1}\) is \(\beta_1+\gamma_1+\cdots+\gamma_j\); before the first knot it is \(\beta_1\). This representation makes the fitted function continuous at each knot, though its slope may change there.

Definition: A knot location is a predictor value at which a piecewise regression model permits a change in slope. With a fixed set of knots, their locations determine where slope changes can occur; they do not, by themselves, determine the sizes or directions of those changes.

For the usual least-squares fit, a standard working model is that the errors have mean zero, are independent across observations, and have constant variance. Normal errors are additionally assumed when exact normal-theory inference is needed. Knot-placement strategies do not make these assumptions true; they concern how the predictor axis is divided. The examples below focus on placement and support, not on testing slope changes.

A knot count fixes the number of hinge terms, but the same count can allocate flexibility very differently. A useful first check is to sort the observed predictor values and note how many fall in each interval. Counts are informative, but not sufficient: the values’ spread within each interval and the gaps between them also matter.

Three Ways to Choose Knot Locations

Substantively chosen knots use prior knowledge about the setting. A knot might represent a known policy threshold, a change in measurement procedure, or a scientifically meaningful dose level. This is useful when the location has an interpretation independent of the observed outcome. A meaningful threshold is not automatically supported by the data, however: observations near it are needed to learn whether the fitted slope changes there.

Evenly spaced knots divide the predictor’s observed range into intervals of equal width. For \(m\) knots over a range from \(x_{\min}\) to \(x_{\max}\), the spacing is \((x_{\max}-x_{\min})/(m+1)\). This provides a regular layout in predictor units, but it says nothing about how many observations fall into each interval.

Predictor-quantile knots use quantiles of the observed \(x\) values. Their aim is to make the number of observations in each resulting segment roughly similar. Quantiles need a stated calculation convention, particularly for small data sets. In the worked example below, the sample quantile at probability \(p\) is defined by the position \(1+(n-1)p\) in the sorted values, with linear interpolation between adjacent values when needed.

Worked Example: Choosing a Knot at a Meaningful Threshold

Suppose a hypothetical study records a response \(Y\) and dose \(x\), measured in milligrams, for a group of individuals. Based on subject-matter knowledge, investigators identify 40 mg as a meaningful dose threshold before examining the response pattern. They choose one fixed knot, \(k=40\), and obtain this illustrative fitted model:

$$ \widehat{Y}=12+0.30x+0.20(x-40)_+ $$

Below 40 mg, the hinge term is zero, so the fitted slope is \(0.30\) response units per milligram. Above 40 mg, the slope is \(0.30+0.20=0.50\) response units per milligram. The knot gives the model room to represent a slope change at the prespecified threshold; it does not prove that the slope truly changes there.

For a dose of 30 mg, the hinge contribution is \((30-40)_+=0\), giving \(\widehat{Y}=12+0.30(30)=21\) response units. At 50 mg, the hinge contribution is \((50-40)_+=10\), giving \(\widehat{Y}=12+0.30(50)+0.20(10)=29\) response units. The placement is substantively interpretable, but its empirical usefulness still depends on how many observed doses lie near 40 mg. If the data contain no doses near the threshold, the fitted change there may be weakly supported despite its scientific rationale.

Worked Example: Comparing Even Spacing and Predictor Quantiles

Consider these hypothetical sorted predictor values: \(0,1,2,3,4,5,6,7,8,9,10,20\). There are \(n=12\) observations, and the range is from 0 to 20. To place three evenly spaced knots, divide the range into four equal-width intervals. The width is \((20-0)/(3+1)=5\), so the knots are 5, 10, and 15.

Assign values equal to a knot to the interval ending at that knot. The four intervals \([0,5]\), \((5,10]\), \((10,15]\), and \((15,20]\) contain 6, 5, 0, and 1 observations, respectively. The knot locations cover the range regularly, but one segment has no observations in it and the last has only one. Thus, equal widths do not ensure that every part of the fitted curve is well supported.

Now place knots at the sample quartiles \(p=0.25,0.50,0.75\), using position \(1+(n-1)p\). The positions are \(1+11(0.25)=3.75\), \(1+11(0.50)=6.5\), and \(1+11(0.75)=9.25\). Linear interpolation gives knots \(2.75\), \(5.5\), and \(8.25\). The intervals \([0,2.75]\), \((2.75,5.5]\), \((5.5,8.25]\), and \((8.25,20]\) each contain 3 observations.

The quantile knots balance the counts in this example, but not the widths of the intervals. In particular, the final interval is \(20-8.25=11.75\) predictor units wide, while the first is only \(2.75\) units wide. The final interval also includes the large gap from 10 to 20. Equal counts therefore do not mean equal coverage of the predictor range or equally precise local slope information.

Segment Coverage and Sparse Regions

The previous example illustrates two different ideas of coverage. Even spacing provides equal coverage in predictor units; quantile placement aims for similar coverage in observation counts. Neither guarantees that observations are spread through each segment. Several observations tightly clustered at one end of an interval may offer less information about its slope than the same count spread across the interval.

A segment with very few observations can make its local behavior weakly supported. In a continuous piecewise linear model, the fitted slopes are linked through the hinge coefficients, so the slope in a segment is not generally estimated from that segment alone. Still, a region with little data provides limited direct information about how the fitted curve behaves there. A knot placed inside a gap can let the model change slope where there are no nearby observations to clarify whether that change is warranted.

Quantile knots also have practical limitations. Ties among predictor values can put multiple quantiles at the same value, so the resulting knots may not be distinct. A high-density cluster may then leave a broad, sparsely observed tail. At the other extreme, evenly spaced knots can leave some segments nearly empty when predictor values are highly concentrated in only part of the range. In either case, inspect the values and segment counts rather than relying on the placement rule alone.

Worked Example: Diagnosing a Knot in a Sparse Region

Suppose a second hypothetical data set has sorted predictor values \(0,1,2,3,4,5,6,7,8,9,10,30,50\). Consider three evenly spaced knots over the range \([0,50]\). The spacing is \((50-0)/(3+1)=12.5\), so the knots are \(12.5\), \(25\), and \(37.5\).

The intervals \([0,12.5]\), \((12.5,25]\), \((25,37.5]\), and \((37.5,50]\) contain 11, 0, 1, and 1 observations. Although the knots are evenly spaced, most observations are in the first interval; the middle interval has none. A slope change at 25 mg, for example, would be located inside the gap from 10 to 30 mg.

For comparison, use the same quantile convention as before. With \(n=13\), the quartile positions are \(1+12(0.25)=4\), \(1+12(0.50)=7\), and \(1+12(0.75)=10\). The corresponding predictor values are 3, 6, and 9. The intervals \([0,3]\), \((3,6]\), \((6,9]\), and \((9,50]\) contain 4, 3, 3, and 3 observations.

The quantile placement balances the counts, but the final interval extends from 9 to 50 and contains the values 10, 30, and 50. Its three observations are widely separated, with no observations between 10 and 30. Neither strategy supplies dense local coverage throughout that tail. The example shows why a segment count should be checked alongside its width, the spread of its predictor values, and any large gaps.

A Practical Knot-Placement Check

Knot choice should match the goal of the analysis, not just a convenient formula. A substantive threshold is attractive when it has a defensible meaning independent of the response pattern. Even spacing is transparent when coverage across the predictor scale is the main priority. Quantiles can be helpful when predictor values are unevenly distributed and a roughly balanced number of observations per segment is desirable. In practice, it is useful to compare the candidate locations against both the data distribution and the question being asked.

1
State the basis for the locations.
Record whether knots come from a meaningful threshold, equal divisions of the predictor range, or predictor quantiles. This makes clear what the choice is intended to accomplish.
2
Check the segments.
Count observations in each interval and inspect their spread. Note empty or thin intervals, tightly clustered values, and large gaps near knots.
3
Match flexibility to support.
Ask whether the data near each knot can inform the permitted slope change. If not, reconsider the location or the amount of flexibility rather than treating the knot rule as automatic.
4
Keep interpretation clear.
Explain what the knot locations represent and avoid describing a data-driven placement as a scientifically established threshold.

A further caution concerns using the response to choose knot locations. If locations are selected after searching for places that make the observed response pattern look especially favorable, the resulting fit may reflect that search as well as the underlying relationship. Predictor-only quantiles avoid using response values to place knots, while substantive choices should be justified independently of the observed response. Whatever the choice, knot locations describe where the model can bend, not evidence on their own that a real change in slope occurs.

Common Mistake

Common mistake: “The quantile knots put the same number of observations in each segment, so every segment is equally well supported.” Correction: Equal counts do not guarantee similar predictor spread, observations near the knots, or an absence of long gaps. Check both the counts and the locations of the observed predictor values; a segment with several widely separated observations may still have little local coverage.

A related mistake is treating a scientifically meaningful knot as automatically estimable. A known threshold can make a location easier to explain, but it does not create observations around that threshold. Placement is a modeling decision whose justification should include both the reason for the knot and the data available to support the flexibility it introduces.

Check Your Understanding

Use the definitions and placement checks above to answer these questions.

  1. For predictor values ranging from 10 to 50, where would two evenly spaced internal knots be placed?
  2. In what sense do predictor-quantile knots aim to balance segments, and what aspect of coverage do they not ensure?
  3. Why might a substantively important threshold still be weakly supported by the observed data?
  4. A segment contains five observations, all clustered near one endpoint. What additional information would you inspect before judging its coverage?
  5. Why can a knot in a large gap offer flexibility that the data cannot directly inform well?