plausibel, and kindly contributed to Want to share your content on R-bloggers? [This article was first published on, and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

As a first step to produce some useable code for spline interpolation/approximation in R, I set out to first do polynomial interpolation to see how I get along. It’s not that there is no spline interpolation software for R, but I find it a bit limited. splinefun, for example, can do only 1-dimensional interpolation. interp{akima} can do bicubic splines – i.e. it can fit a spline surface to a set of points over gridded data as for example (x,y,f(x,y)). However, x and y need to have the same length. There’s no apparent reason for this, and it might be inefficient to have to do this at times, so I’ll be looking at changing that.

As a first step, I’ll implement a polynomial approximation algorithm. The basic principle is that of a convex hull of points in a given space. By repeatedly taking convex combinations of points one builds up the approximating curve. The theoretical background for this can be looked up here . The algorithm I implement here is a variant of the DeBoor triangular calculation. I am not claiming this to be the most efficient calculation, this is just a first try. Way too many loops.

So: I sample different number of points on a half circle and construct an interpolating polynomial. you can see the result in the graph below. the red line is the polynomial approximation. the code is added below the graph.

here is the code:

# test polynomial interpolation code by interpolating points on a semi-circle # using a different number of points each time. # contents: # 1) make.circle(degree) is a function that generates # n=degree+1 data points (x,y) on a semicircle. this is the "data" we # want to interpolate. # 2) pinterp() makes polynomial interpolation on "data" of degree "degree" # using degree+1 parameters # 3) run() is a wrapper that runs the interpolation # note: polynomial interpolation uses n=degree+1 points and T=degree+1 parameters. # # output: # plot of the interpolation overlaid by the used data points rm(list=ls(all=TRUE)) setwd("~/dropbox/Rstuff/splines") require(plotrix) # this package contains a function to draw a circle. # you could generate any other data as well. # task: run this approximation for 3,7,11 and 15 sample points. degrees =0, ] # take only upper half of circle§ return(data) } pinterp