# BSplines: how many segments spanned by a basis function of order K

I'm trying to teach myself Basis splines, from what I have read a basis spline of order K is non-zero in K segments only. Is this correct? I ask because when I use the following code to plot basis splines in R, some of the basis functions only span 2 or 3 segments (first dotted line from left etc.). May be it is just a convention in R, I mainly just want to make sure I understand the concept correctly.

Edit: Based on this link, it seems not all the basis splines produced in this plot are of degree 3. I should add 3 dummy knots on either end to get cubic bsplines between my input data range. Is this correct. library(splines)
x = seq(1,10,0.01)
b = bs(x, knots = c(2.5, 5, 7.5), degree = 3, intercept = TRUE)
matplot(x, b, type = 'l')
abline(v = c(2.5, 5, 7.5), lty = 2)


EDIT: Below I produce 2 examples of fitting cubic bsplines (line in both the charts) to hypothetical data(dots in both the charts) for x between [0,4]. With 2 imaginary knots (knots at -2,-1,0,1,2,3,4,5,6), the fit is not very good but with 3 imaginary knots (knots at -3,-2,-1,0,1,2,3,4,5,6,7) it is perfect. • Notice the knots at begin and end are repeated. Either you count the multiplicity of repeating knots (that is zero length segments), or you correct your statement to "non-zero" on $K$ segments at most. Aug 31, 2016 at 19:17

Suppose we're dealing with basis functions of order $k$ (i.e. degree = $k-1$) on the knot sequence $(t_i)$. Then the $i$-th b-spline basis function is non-zero on the interval $[t_i, t_{i+k}]$. If $t_i < \ldots < t_{i+k}$, then there are $k$ "segments" between $t_i$ and $t_{i+k}$. But if some of these knots are equal, then some of these $k$ segments will shrink to zero, so you may choose to not count them as segments at all.
In the example you plotted, it looks like your software automatically added some extra (and duplicated) knots at the ends of your curve. This is a common practice. So, though you asked for knots $(2.5, 5, 7.5)$, you actually got knots $(0,0,0,0,2.5,5,7.5,1,1,1,1)$. The repeated knots give you zero-length segments, and this throws off your segment-counting scheme.
• Using 4 zeros and 4 ones on a cubic spline is "traditional". If you go through the math, you will find that the b-spline value does not actually depend on the first and last knots. So, the first knot can be anything you like, as long as it's $\le0$, so you could actually omit it. Same for the last knot. The purpose of the added (repeated) knots is to get interpolation of the first and last control points. But this is not always what you want. Sep 6, 2016 at 0:11