splinefun                package:base                R Documentation

_I_n_t_e_r_p_o_l_a_t_i_n_g _S_p_l_i_n_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Perform cubic spline interpolation of given data points, returning
     either a list of points obtained by the interpolation or a
     function performing the interpolation.

_U_s_a_g_e:

     splinefun(x, y = NULL, method = "fmm")

     spline(x, y = NULL, n = 3*length(x), method = "fmm",
            xmin = min(x), xmax = max(x))

_A_r_g_u_m_e_n_t_s:

     x,y: vectors giving the coordinates of the points to be
          interpolated.  Alternatively a single plotting structure can
          be specified: see 'xy.coords.'

  method: specifies the type of spline to be used.  Possible values are
          '"fmm"', '"natural"' and '"periodic"'.

       n: interpolation takes place at 'n' equally spaced points
          spanning the interval ['xmin', 'xmax'].

    xmin: left-hand endpoint of the interpolation interval.

    xmax: right-hand endpoint of the interpolation interval.

_D_e_t_a_i_l_s:

     If 'method = "fmm"', the spline used is that of Forsythe, Malcolm
     and Moler (an exact cubic is fitted through the four points at
     each end of the data, and this is used to determine the end
     conditions). Natural splines are used when 'method = "natural"',
     and periodic splines when 'method = "periodic"'.

     These interpolation splines can also be used for extrapolation,
     that is prediction at points outside the range of 'x'. 
     Extrapolation makes little sense for 'method = "fmm"'; for natural
     splines it is linear using the slope of the interpolating curve at
     the nearest data point.

_V_a_l_u_e:

     'spline' returns a list containing components 'x' and 'y' which
     give the ordinates where interpolation took place and the
     interpolated values.

     'splinefun' returns a function which will perform cubic spline
     interpolation of the given data points.  This is often more useful
     than 'spline'.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

     Forsythe, G. E., Malcolm, M. A. and Moler, C. B. (1977) _Computer
     Methods for Mathematical Computations_.

_S_e_e _A_l_s_o:

     'approx' and 'approxfun' for constant and linear interpolation.

     Package 'splines', especially 'interpSpline' and 'periodicSpline'
     for interpolation splines. That package also generates spline
     bases that can be used for regression splines.

     'smooth.spline' in package 'modreg' for smoothing splines.

_E_x_a_m_p_l_e_s:

     op <- par(mfrow = c(2,1), mgp = c(2,.8,0), mar = .1+c(3,3,3,1))
     n <- 9
     x <- 1:n
     y <- rnorm(n)
     plot(x, y, main = paste("spline[fun](.) through", n, "points"))
     lines(spline(x, y))
     lines(spline(x, y, n = 201), col = 2)

     y <- (x-6)^2
     plot(x, y, main = "spline(.) -- 3 methods")
     lines(spline(x, y, n = 201), col = 2)
     lines(spline(x, y, n = 201, method = "natural"), col = 3)
     lines(spline(x, y, n = 201, method = "periodic"), col = 4)
     legend(6,25, c("fmm","natural","periodic"), col=2:4, lty=1)

     f <- splinefun(x, y)
     ls(envir = environment(f))
     splinecoef <- eval(expression(z), envir = environment(f))
     curve(f(x), 1, 10, col = "green", lwd = 1.5)
     points(splinecoef, col = "purple", cex = 2)
     par(op)

