# What are the representations of splines? Is there a concept of a 0 degree spline?

The splines package in R is mostly focused on, what they call, a B-spline representation which is, by default, a cubic polynomial with no knots (unless you supply them). The actual numeric coding of the splines is described well in the package. Needless to say, it's a little sophisticated. Case in point:

x <- 1:100
matplot(x, bs(x, knots=c(25, 50, 75)), type='l')


gives

The argument bs(x, knots=c(25, 50, 75)) produces a 6 column matrix of output. What are the columns of a spline representation technically referred to as? Inputs? Curves?

But I am interested in a constant sort of "moving average" representation to interpolate low order ordinal variables and estimate a specific contrast which clusters adjacent categories for better predictive accuracy. With the basis spline representation, degree 1 polynomial (aka linear) splines are square waves:

Needless to say, in a linear model, I feel this is anything but intuitive. I'm not sure if the regression model which regresses an outcome against a linear basis spline with knots has any obvious interpretation. Does this square wave ensure that the first term in a regression model is interpreted as the slope for that subsection and the second the second slope, and so on? As far as I know similar predicted values are obtained using code like:

spl <- function(x, knots) {
out <- outer(x, knots, -)
out[out < min(x)] <- min(x)
cbind(x, out)
}


the "representation" is different, but I don't know how to refer to it, and it produces the same predicted values as the other spline,

x <- 1:100
y <- rnorm(100, sin(pi*x/50), 0.5)
par(mfrow=c(1,3))
matplot(sp.1 <- spl(x, 1:3*25), type='l')
matplot(sp.2 <- bs(x, degree=1, knots=1:3*25), type='l')
plot(x, y)
lines(predict(lm(y ~ sp.1)))
lines(predict(lm(y ~ sp.2)))


The linear interpolation of ordinal values is perhaps appropriate to test the hypothesis is there are locally linear approximations to ordinal values. Alternately, we might be interested in a "cumulative mean difference" for regions where a constant interpolation may be appropriate, like a "0 degree spline", which seems nonsensical, but an alternate designation could be something like:

spl0 <- function(x, knots) {
outer(x, knots, <)*1
}


so that predicted values are of the nature:

sp.2 <- spl0(x, 1:3*25)
par(mfrow=c(1,2))
matplot(sp.2, type='l')
plot(x, y)
lines(predict(lm(y ~ sp.2)))


# To summarize my questions:

1. I'm aware of B-splines representations and how they are calculated. What other representations are there and how are they calculated?
2. In spline representation, a single vector is expanded to a matrix with columns. What are the columns referred to as? For instance, in a cubic polynomial representation, the specific terms can be called a linear, quadratic, and cubic term.
3. Are there 0 degree splines? If not, what may I call the "moving average" type of regression I fit in the last example (knowing of course that a moving average is a different type of model)?
4. Are there examples of using a regression of the above type to cluster adjacent categories in regression models for ordinal data to obtain parsimonious prediction and inference?
• A "zero degree spline" is ordinarily called a step function. Could you clarify your question? Is it any more than asking for that name? BTW, splines and moving averages are fairly different forms of analysis: one is a tool for regression and the other for smoothing. They are computed in rather different ways, for different purposes. – whuber Jun 8 '17 at 22:28
• @whuber yes I am shakey on the terminology and would appreciate clarification in cases such as where you describe. I understand a moving average does not (necessarily) have pre-specified break-points. – AdamO Jun 8 '17 at 22:32
• Okay, but could you express some definite questions? There are a few embedded in this post en passant, but because they are varied in nature and appear to address only the shallower aspects of the subject, they seem to make the post broader and vaguer than it need be. Consider starting or concluding your remarks with the one (or a small number of related) questions you want addressed. – whuber Jun 8 '17 at 22:36
• The Wikipedia article may be worth a skim. In particular, B-splines are commonly derived/generated by starting with the 0-order (step function) version, and then iteratively convolving. And the derivative of an order-p B-spline is the difference of adjacent order p-1 B-splines. The usefulness of the representation is the local support of the basis functions. This is similar to orthogonal polynomials, in that inner-product matrices are sparse and (block-)diagonal. The locality simplifies refinement as well (e.g. adding knots), used in CAD and FEM. – GeoMatt22 Jun 9 '17 at 2:01
• @whuber I tried to summarize the questions in an edit at the bottom. I hope this is clearer. – AdamO Jun 9 '17 at 16:21