monotoneSpline(x, y, n = 3 * length(x), xmin= min(x), xmax= max(x), newx = <<see below>>, boundary = <<see below>>)
y
values must be monotone (ties are allowed).
Missing values (NA) are allowed.
newx
is supplied.
x
values.
This is ignored if
newx
is supplied.
x
.
Default values include all input values plus values equally spaced
between each pair of neighboring input
x
values.
Missing values (NA) are allowed.
newx
x
values.
The result is a piecewise cubic function which is continuous and has a continuous first derivative. It does not have a continuous second derivative (in contrast to ordinary cubic splines). Extrapolation is linear.
The result is a "local" fit, with any output point affected by at most two knots (input points) on each side.
The algorithm first determines derivatives at all knots, then evaluates piecewise cubic polynomials using these derivatives. Derivatives at interior knots are calculated using the slopes of adjacent secant lines.
Derivatives at exterior knots are determined by the
boundary
argument, which gives the ratio of the derivative at each end knot to
the slope of the adjacent secant line.
For example, the derivative at
min(x)
is the
product of
boundary[1]
and the slope of the secant line
interpolating the two leftmost data points.
The ratio must be positive and not exceed a certain value
to ensure a monotone result,
which varies between 3 and 4 depending on the nearby data;
an error occurs if it
boundary
is too large.
A negative value of
boundary
indicates that the ratio which
minimizes the (local) L2 norm of the result should be used.
If
x
was not sorted, both
x
and
y
will be reordered.
Fritsch, F.N. and Butland, J. (1984), "A Method for Constructing Local Monotone Piecewise Cubic Interpolants," SIAM J. Sci. Stat. Computing, 5(2), 300-304.
x <- ppoints(10) y <- log(x) plot(x, y) lines(monotoneSpline(x, y))