Tutorials › Regression Analysis (Undergraduate) › B-Spline Bases and Local Support

Piecewise Regression and Splines · Tutorial 457 of 991

B-Spline Bases and Local Support

Build B-spline basis functions from a knot sequence, identify their local support, and calculate how their weighted sum produces a fitted spline curve.

Advanced 10 min read

What You'll Learn

  • Define B-spline basis functions recursively from degree-zero interval indicators.
  • Calculate basis values using the Cox–de Boor recursion.
  • Identify the knot-span support of a degree-p B-spline.
  • Explain why only a small number of coefficients affect a fitted value at a given predictor value.
  • Calculate fitted spline values as weighted sums of basis values and coefficients.
  • Distinguish spline coefficients from observed responses and from ordinary polynomial coefficients.

Why Use B-Spline Bases?

A cubic regression spline can be represented with a truncated power basis, as in the earlier material on that basis. That representation is useful for seeing how polynomial pieces are joined, but its columns can be strongly related to one another, and changes to a coefficient may affect a broad part of the curve. A B-spline basis provides another way to represent the same kind of spline: it builds the curve from basis functions that are nonzero only over a limited range of the predictor.

This limited range is called local support. It makes the representation practical: at a given predictor value, only a few B-spline basis functions contribute to the fitted value. The curve is still a weighted sum, with coefficients estimated from data, but its basis functions are organized around the knot sequence.

Definition: A B-spline basis function is a piecewise-polynomial function defined recursively from a nondecreasing knot sequence. Its degree determines the degree of its polynomial pieces. For degree \(p\), the function indexed by \(i\) has support from knot \(t_{i-1}\) to knot \(t_{i+p}\); it is zero outside that range.

Definition by Recursion

Let the knots be \(t_0,t_1,\ldots,t_m\), in nondecreasing order. To keep the calculations transparent here, assume the knots are distinct. Knot multiplicity and its effect on continuity are a separate issue. Define the degree-zero functions as indicators of consecutive half-open intervals:

$$ B_{i,0}(x)= \begin{cases} 1, & t_{i-1}\le x<t_i,\\ 0, & \text{otherwise}. \end{cases} $$

For degrees \(p\ge 1\), define the functions recursively:

$$ B_{i,p}(x)= \frac{x-t_{i-1}}{t_{i+p-1}-t_{i-1}}B_{i,p-1}(x) + \frac{t_{i+p}-x}{t_{i+p}-t_i}B_{i+1,p-1}(x). $$

A term with a zero denominator is defined to be zero. With distinct knots, the denominators in these expressions are positive. Each new degree combines two functions from the preceding degree, multiplying them by weights that vary linearly with \(x\). The resulting function is piecewise polynomial of degree at most \(p\). In regression splines, degree \(p=3\) gives cubic pieces.

The indexing above starts a degree-zero function on \([t_{i-1},t_i)\). State the indexing convention when calculating values: formulas written with other index conventions can shift the labels even though they describe the same shapes.

Support: The support of a function is the range outside which it is zero. The recursion implies that \(B_{i,p}(x)=0\) outside \([t_{i-1},t_{i+p})\). Thus a degree-\(p\) basis function covers \(p+1\) consecutive knot intervals when the knots are distinct.

Worked Example: Applying the Recursion at a Knot

Worked Example: Applying the Recursion at a Knot

Take equally spaced knots \(t_j=j\) for \(j=0,1,\ldots,7\), and evaluate the cubic basis function \(B_{2,3}(x)\) at \(x=3\). The half-open convention makes \(B_{3,0}(3)=0\) and \(B_{4,0}(3)=1\), since \(3\) belongs to \([3,4)\).

First calculate the degree-one terms needed. The recursion gives \(B_{2,1}(3)=0\): its degree-zero terms \(B_{2,0}(3)\) and \(B_{3,0}(3)\) are both zero. For the next index,

$$ B_{3,1}(3) = \frac{3-2}{3-2}B_{3,0}(3) + \frac{4-3}{4-3}B_{4,0}(3) =0+1=1. $$

Now apply the recursion for degree two:

$$ B_{2,2}(3) = \frac{3-1}{3-1}B_{2,1}(3) + \frac{4-3}{4-2}B_{3,1}(3) =1(0)+\frac12(1)=\frac12. $$

The other degree-two value needed is \(B_{3,2}(3)\). Here \(B_{4,1}(3)=0\), because the degree-zero terms used to construct it lie on intervals to the right of \(x=3\). Therefore,

$$ B_{3,2}(3) = \frac{3-2}{4-2}B_{3,1}(3) + \frac{5-3}{5-3}B_{4,1}(3) = \frac12(1)+1(0)=\frac12. $$

Finally, the cubic value is

$$ B_{2,3}(3) = \frac{3-1}{4-1}B_{2,2}(3) + \frac{5-3}{5-2}B_{3,2}(3) = \frac23\left(\frac12\right)+\frac23\left(\frac12\right) = \frac23. $$

The calculation shows why the lower-degree terms must be evaluated carefully before applying the final recursion. In particular, both degree-two terms here equal \(1/2\); replacing either with an incorrect value changes the result.

Local Support and Which Coefficients Matter

The support statement follows directly from the recursion. A degree-zero function \(B_{i,0}\) is zero outside \([t_{i-1},t_i)\). Suppose each degree-\((p-1)\) function is zero outside its stated support. In the degree-\(p\) recursion, the first term can be nonzero only where \(B_{i,p-1}\) can be nonzero, and the second only where \(B_{i+1,p-1}\) can be nonzero. Those ranges are \([t_{i-1},t_{i+p-1})\) and \([t_i,t_{i+p})\). Their union is contained in \([t_{i-1},t_{i+p})\). This proves the support result by induction on \(p\).

For a cubic basis function, the support is \([t_{i-1},t_{i+3})\). If knots are distinct, this includes four consecutive knot intervals. So a change to one cubic coefficient affects the curve only across that function's support. At an \(x\) lying between two consecutive knots, at most four cubic B-spline basis functions can be nonzero. This is the local character of the basis.

Worked Example: Tracing the Range of a Coefficient's Effect

Suppose the knots are \(0,1,\ldots,7\), and a cubic spline includes the basis function \(B_{2,3}\). Its support is

$$ [t_{2-1},t_{2+3})=[t_1,t_5)=[1,5). $$

Consider two fitted curves with the same basis functions and the same coefficients except that the coefficient multiplying \(B_{2,3}\) is 3 units larger in the second curve. The difference between the fitted curves at \(x\) is \(3B_{2,3}(x)\). For \(x<1\) or \(x\ge 5\), the basis function is zero, so the fitted curves agree there. Within the support, the difference varies according to the value of the basis function.

At \(x=3\), the preceding recursion calculation gives \(B_{2,3}(3)=2/3\). The fitted curves therefore differ by

$$ 3B_{2,3}(3)=3\left(\frac23\right)=2 $$

response units at that predictor value. Local support does not mean the coefficient changes the fit by a constant amount throughout the support; it means only that its effect is confined to that range.

A Fitted Spline Is a Weighted Sum

For observations with predictor values \(x_1,\ldots,x_n\) and responses \(y_1,\ldots,y_n\), a regression spline can be written as a sum of B-spline basis functions. For a cubic spline with \(K\) basis functions, a common model is

$$ Y_j=\sum_{i=1}^{K}c_iB_{i,3}(x_j)+\varepsilon_j, \qquad j=1,\ldots,n. $$

Here \(c_i\) is the coefficient multiplying basis function \(B_{i,3}\), and \(\varepsilon_j\) is the error for observation \(j\). For the usual linear regression interpretation, assume the errors have mean zero and constant variance and are independent across observations. Normal errors are additionally needed for exact small-sample \(t\)- and \(F\)-inference, but not for evaluating a fitted curve. Once the coefficients have been estimated, the fitted value at any \(x\) is

$$ \hat{y}(x)=\sum_{i=1}^{K}\hat{c}_iB_{i,3}(x). $$

The estimate \(\hat{y}(x)\) is a weighted sum: the basis values at \(x\) are the weights, and the estimated coefficients are the quantities being weighted. For cubic B-splines, only the functions whose supports contain \(x\) contribute. If the basis is constructed over a suitable knot sequence and evaluated in its spline domain, the B-spline basis functions are nonnegative and sum to one at each point in that domain. Consequently, the fitted value is a weighted average of the contributing coefficients there. This does not mean that a coefficient is generally the fitted response at a particular observation.

Worked Example: Calculating a Fitted Value From Basis Weights

Continue with knots \(0,1,\ldots,7\) and cubic basis functions indexed \(B_{1,3},\ldots,B_{4,3}\). The spline domain for this knot vector is \([t_3,t_4]=[3,4]\). At \(x=3\), recursion gives the nonzero basis values \(B_{1,3}(3)=1/6\), \(B_{2,3}(3)=2/3\), and \(B_{3,3}(3)=1/6\); \(B_{4,3}(3)=0\). These values sum to one.

Suppose a hypothetical fitted model has coefficients \(\hat{c}_1=10\), \(\hat{c}_2=14\), \(\hat{c}_3=20\), and \(\hat{c}_4=26\), measured in response units. The fitted response at \(x=3\) is

$$ \begin{aligned} \hat{y}(3) &=\frac16(10)+\frac23(14)+\frac16(20)+0(26)\\ &=\frac{10}{6}+\frac{28}{3}+\frac{20}{6}\\ &=14.333. \end{aligned} $$

Thus the fitted response is approximately \(14.33\) response units at \(x=3\). It is not equal to any one coefficient: it combines the coefficients according to the local basis weights. The fourth coefficient has no effect at this particular point because its basis value is zero.

How B-Spline Bases Relate to Regression

Once the basis functions and knots are fixed, the model is linear in its coefficients even though the fitted curve can bend. For each observation, evaluate each basis function at its predictor value. These evaluations form a design matrix: rows correspond to observations, and columns correspond to basis functions. Estimating the spline is then a linear regression using those columns. The nonlinearity is in the relationship between \(x\) and the fitted response, not in the way the coefficients enter the model.

B-spline and truncated power bases can represent the same spline space when constructed for the same degree, knots, and boundary setup. They express that space in different coordinates. B-splines are especially useful computationally because local support makes the design matrix sparse: most basis columns are zero for any one observation. This can reduce computation and makes the local effect of a basis coefficient easier to track.

The coefficient values themselves should not be read as segment slopes or as response values at knots. A coefficient scales a basis function; a fitted response is obtained by adding the contributions from all basis functions at the chosen \(x\). The curve, rather than an isolated coefficient, is usually the direct object of interpretation.

Common Mistakes

  • Using the wrong lower-degree values. The recursion is only as accurate as its inputs. Calculate the degree-zero and intermediate terms at the stated \(x\) before substituting into the next degree.
  • Ignoring endpoint conventions. With half-open degree-zero intervals, a knot belongs to the interval beginning at that knot, not the interval ending there. Use the convention consistently in recursive calculations.
  • Assuming a coefficient affects the whole fitted curve. A B-spline coefficient changes the fitted curve only over the support of its basis function.
  • Treating a coefficient as a fitted response. Fitted values are sums of coefficients multiplied by basis values. They are not generally equal to a single coefficient.
  • Confusing basis degree with curve flexibility alone. Degree sets the maximum polynomial degree on each piece; the number and placement of knots also shape the spline space.
Key takeaway: B-spline basis functions are built recursively from knot intervals. A degree-\(p\) function is supported across \(p+1\) consecutive intervals, so only a limited number of coefficients contribute at any predictor value. The fitted spline is the weighted sum of those basis functions and their estimated coefficients.

Check Your Understanding

Use the definitions and examples above to answer these questions.

  1. For a degree-\(p\) B-spline \(B_{i,p}\), state its support using the knot indices in this tutorial.
  2. With knots \(t_j=j\), explain why \(B_{3,0}(3)=0\) but \(B_{4,0}(3)=1\) under the half-open interval convention.
  3. Why can changing one cubic B-spline coefficient affect the fitted curve on only a limited range of \(x\)-values?
  4. If the basis values at a particular \(x\) are \(0.2\), \(0.5\), and \(0.3\), and their coefficients are 8, 12, and 17, calculate the fitted value contributed by these basis functions.
  5. Explain why a B-spline coefficient is not generally the fitted response at a knot.