spline(x, y = NULL, n = 3 * length(x), method = "fmm", xmin = min(x), xmax = max(x), xout, ties = mean) splinefun(x, y = NULL, method = c("fmm", "periodic", "natural", "monoH.FC", "hyman"), ties = mean) splinefunH(x, y, m)
x, y |
vectors specifying the coordinates of points.
|
n | an integer. Specifies the number of output points, equally spaced in the interval[xmin, xmax]. Ignored if xout is supplied. |
method |
a character string. Gives the method to interpolate. Must be one of the following:
|
xmin, xmax | The range of the default value of the xout argument. |
xout | The x values at which to evaluate the interpolating spline. Its default value is seq(xmin, xmax, length=n). If none of these are provided, the spline is evaluated at 3*length(x) equally spaced values covering the range of x. |
ties |
a function or the name of a function specifying how to handle duplicate x values.
|
m | a vector of slopes corresponding to the point (x, y). Used only for splinefunH. |
Method | Description |
"fmm" | The spline used is that of Forsythe, Malcolm, and Moler. |
"periodic" | Periodic splines are used. The period is taken to be diff(range(x)), and it is expected that the y values corresponding to the extrema of x are equal. |
"natural" | Natural splines are used. The second derivative is zero at the endpoints. |
"monoH.FC" | The monotone piecewise cubic interpolation method of F.N. Fritsch and R.E. Carlson (with modifications by Butland and Brodlie) is used. (This is the Fortran routine DPCHIP from the slatec library.) |
"hyman" | Also gives a monotone spline: the "fmm" spline is initially calculated, and then the method of J.M. Hyman is used to force it to be monotone. |
spline | returns a list containing components x and y, the coordinates of the interpolated spline curve. |
splinefun | returns a function with arguments x and deriv(with the default value zero). This function can be used to evaluate the interpolating cubic spline (deriv=0), or its derivatives (deriv=1,2,3) at the points x. |
splinefunH, splinefun(method="monoH.FC") | return a function similar to that returned by splinefun, but
it includes an extra argument, extrapol, giving you options for
how the function behaves outside of the range of the x used to create the spline.
extrapol="linear", the default, specifies linear extrapolation; extrapol="cubic" specifies cubic extrapolation. (Cubic extrapolation usually gives very poor results.) |
spline(1:10, sin(1:10)) f <- splinefun(1:10, sin(1:10)) f(seq(1, 10, len=30)) # same result as y component in first call to splineh <- splinefun(log2(1:20), sort(sin(1:20)), method="hyman") h(seq(0, 4, by=1/8), deriv=1) # all slopes positive
p <- splinefun(log2(1:16), sin(c(1:15,1)), method="periodic") p(seq(0, 5, by=1/4)) # period=4
# define a piecewise cubic in Hermite format that approximates sin(2*x) on [11,14] hm <- splinefunH(x=11:14, y=sin(2*(11:14)), m=2*cos(2*(11:14))) hm(seq(10,15,by=1/2), extrapol="linear")