hyman.filter {posum} | R Documentation |
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.
hyman.filter(z)
z |
A list or dataframe containing at least the following:
|
If z
has other elements, they will be ignored.
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.
Returns the input dataframe/list z
with array b
modified
to ensure co-monotonicity of the cubic Hermite interpolant defined by
x,y,b
.
Simon N. Wood snw@st-and.ac.uk
Hyman (1983) SIAM J. Sci. Stat. Comput. 4(4):645-654
# 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)