spl.coef.conv {posum}R Documentation

Convert Hermite spline coefficients to simple power basis coefficients.

Description

Takes the knot locations and gradients at knots, specifying a piecewise cubic interpolant using cubic Hermite polynomials, and calculates the coefficients of the piecewise polynomials expressed using a simple power basis.

Usage

spl.coef.conv(z)

Arguments

z A data frame or list containing at least:
x,y
x,y points being interpolated by piecewise cubic function of x (continuous to at least first derivative).
b
gradients of piecewise cubic w.r.t. x at each supplied x value - this with x,y is sufficient to determine the piecewise cubic polynomial through the data.

Details

x,y,b are sufficient to uniquely define a C1 piecewise cubic interpolant of the x,y data, using cubic Hermite polynomials, however many routines use the polynomial power basis, and in this case 2 extra coefficients need to be calcualted at each x value - the values of the second and third deriatives of the function, c and d, respectively. This routine does this. Its primary function is to take a Hyman filtered spline based interpolant and obtain the coefficients to enable this to be evaluated using code supplied in the R base package.

Value

The function returns z with new c and d arrays.

WARNING

Author(s)

Simon N. Wood snw@st-and.ac.uk

References

http://www.ruwpa.st-and.ac.uk/simon.html

See Also

cm.splinefun, hyman.filter,

Examples

x<-0:9
y<-c(0,0,2,2,4,4,5,6,7,7)
normal.spl<-splinefun(x,y)
xx<-seq(0,9,length=100)
plot(xx,normal.spl(xx),type="l",col=2,main="Hyman filter demonstration")
n<-length(y)
z <- .C("spline_coef", method = as.integer(2), n = n, 
        x = as.double(x), y = as.double(y), b = double(n), c = double(n), 
        d = double(n),e = double(0), PACKAGE = "base")
z<-hyman.filter(z) # filter gradients for co-monotonicity
z<-spl.coef.conv(z) # force other coefficients to consistency
cm.spl<-function(x) { .C("spline_eval", z$method, length(x), x = as.double(x), 
            y = double(length(x)), z$n, z$x, z$y, z$b, z$c, z$d, 
            PACKAGE = "base")$y}
lines(xx,cm.spl(xx),col=3)
points(x,y)


[Package Contents]