I need to use the "not-a-knot" cubic spline for interpolation in my R scripts.
Although there are some R packages for splines, none of them seem to consider the "not-a-knot" type, even if it is said to be a rather "popular" type of cubic spline, and it is available in Matlab.
I fear that there is another name for "not-a-knot" cubic splines. It is a cubic spline where the two extra conditions are about the third derivative continuity in the second and before-last knots (instead of fixing the first derivatives at the endpoint knots, as natural cubic splines do, or other choices).
By digging a little bit, it seems that this is implemented in
pracma::interp1
From
?pracma::interp1
This doesn't mention "not-a-knot", but I got there by using
sos::findFn("not-a-knot")
, which brought me togsignal::pulstran()
. That function's "spline" method is described as "Spline interpolation using not-a-knot end conditions"; themethod=
argument is passed directly topracma::interp1
.Here is an example comparing:
pracma::interp1
pracma:::.ml.spline
(doesn't do any argument-checking, sorting, duplicate removal ... but does allow extrapolation. I don't know whypracma::interp1
makes this restriction. The package is developed on r-forge but I don't see mailing lists etc., you could contact the maintainer or hackinterp1
yourself ...)RcppOctave
package, but it's archived and I couldn't easily get the package to install viaremotes::install_version("RcppOctave", version = "0.18-1")
- too much configuration drift ...).ml.spline
output agreeinterp1
agrees within the range of the data (no extrapolation)Octave code (run in a separate shell)