hyman.filter {posum}R Documentation

Co-monotonic filtering of cubic Hermite polynomials

Description

Filters the coefficients of an interpolating set of cubic Hermite polynomials to ensure co-monotonicity of the interpolant. Usually the original coefficients will be chosen so that the original interpolant is a cubic spline. Hyman's algorithm works with a set of sufficient conditions for monotonicity so these are slightly more restrictive than is absolutely necessary.

Usage

hyman.filter(z)

Arguments

z A list or dataframe containing at least the following:
x,y
set of x,y points that are to be interpolated - interpolant will be a function of x.
b
gradients of the interpolant w.r.t. x at the x values. It is these values that will be modified to ensure co-monotonicity.

If z has other elements, they will be ignored.

Details

Basically limits on allowable values of b can be obtained from looking at the gradients of the piecewise linear interpolant through x,y: see Hyman (1983) for full details.

Value

Returns the input dataframe/list z with array b modified to ensure co-monotonicity of the cubic Hermite interpolant defined by x,y,b.

WARNING

Author(s)

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

References

Hyman (1983) SIAM J. Sci. Stat. Comput. 4(4):645-654

See Also

cm.splinefun,spl.coef.conv

Examples

# example partly modified from cm.splinefun
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]