0

I am trying to create a B-spline basis of order 4 for a data set of 106 with 40 internal knots. All the plotted basis functions I've seen so far consists of very smooth and nicely spread out curves, whereas mine is pointy and generally pretty ugly looking. Is this a property of having such a low ratio of data points compared to knots or am I doing something horribly wrong?

And if it is a property, should I generate more data before creating the spline basis?

require(splines)
set.seed(100)
x = sort(runif(106, 91.78525, 123))
equidistant.knots = seq(min(x) + 0.761, max(x) - 0.761, length=40)
equidistant.ret = bs(x, knots = equidistant.knots, degree = 4, intercept = FALSE, Boundary.knots = range(x))
plot(equidistant.ret[,1]~x, ylim=c(0,max(equidistant.ret)), type='l', lwd=2, col=1, 
 xlab="Cubic B-spline basis", ylab="")
for (j in 2:ncol(equidistant.ret)) lines(equidistant.ret[,j]~x, lwd=2, col=j)

More spiky basis functions

estenhl
  • 59
  • 9
  • Please consider reading up on [ask] and how to produce a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Heroka Nov 19 '15 at 15:58
  • My bad, should be easier now :) – estenhl Nov 19 '15 at 16:09
  • Where does the 'bs'-function come from? – Heroka Nov 19 '15 at 16:11
  • splines-package, https://stat.ethz.ch/R-manual/R-devel/library/splines/html/bs.html. Added it to the code now – estenhl Nov 19 '15 at 16:29
  • 1
    The spline basis is smooth (mathematically it must be smooth), but you're only sampling the basis at your data points. If you want a smooth plot of your basis you should oversample the interval and plot the spline function at those points. --- If I fit a parabola to 5 points my fit will be a smooth parabola, but if I only plot it at those 5 points and connect them with straight lines the low-res picture of the smooth parabola will have corners. You need to increase the resolution of your picture, which means calculating the spline for more points than where your data are. – Gregor Thomas Nov 19 '15 at 17:02

0 Answers0