4
$\begingroup$

I am confused about how the degrees of freedom in a B-spline are calculated in the package splines. The documentation for the B-spline function can be found here:

https://www.rdocumentation.org/packages/splines/versions/3.6.2/topics/bs

With this function, the degrees of freedom for a spline fit are calculated as:

df = length(knots) + degree

where "knots" refers only to interior knots and "degree" refers to the degree of the polynomial you are fitting.

Take a case of a cubic spline with one interior knot. length(knots) = 1. Since the degree of a polynomial is 3, "degree" is 3. So df = 4.

However, isn't the knot in the spline conjoining two cubic polynomials, each with three adjustable parameters? In that case, shouldn't df in fact be 7?

The reason I'm interested is that I want to know how to calculate QICC (a cousin of AIC) for a model based on a spline. A model's QICC score reflects the number of estimated parameters in the model. In the case of one internal knot, is the penalty equal to the degrees of freedom (as reported in summary = 4 (= 1 knot + 3 coefficients)) or is the penalty equal to 7 (= 1 knot + 3 coefficients for the polynomial to the left of the knot + 3 coefficients for the polynomial to right of knot)?

What am I missing?

$\endgroup$

1 Answer 1

6
$\begingroup$

Cubic splines are not just many third-degree polynomials with knots marking the transitions between one polynomial and another, they are constrained third-degree polynomials with knots marking the transitions. The most obvious, to the naked eye, is the constraint that at the knot, the value of the polynomial to the "left" of the knot equals the value of the polynomial to the "right" of the knot. Intuitively, you can see that this constrains the value of the intercept of either the left or right polynomial to equal whatever value makes the two polynomials equal at the knot - costing you a degree of freedom.

Similarly, the first and second derivatives of the left and right polynomials are constrained to be equal at the knot, costing you two more degrees of freedom. Hence the seven degrees of freedom becomes four. These constraints are what make splines "splines" instead of just disjoint polynomials. They make the overall function, comprised of splines, smooth to a certain degree (two, in the case of cubic splines.)

In general, a $k^{th}$ degree spline will have $k-1$ constraints at each of the knots. Since there are, let us say, $m$ knots, we have $m+1$ polynomials, giving us $k(m+1) - (k-1)m = k+m$ degrees of freedom.

$\endgroup$
1
  • $\begingroup$ Wonderful. Thank you for this explanation—it's clear as a bell. $\endgroup$
    – Brian M.
    Commented Jul 13, 2022 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.