Monotone Piecewise Cubic Spline

DESCRIPTION:

Fit a monotone interpolating curve through the data points using cubic splines with continuous first derivatives.

USAGE:

monotoneSpline(x, y, n = 3 * length(x), 
    xmin= min(x), xmax= max(x), newx = <<see below>>, 
    boundary = <<see below>>) 

REQUIRED ARGUMENTS:

x,y
coordinates of points. The coordinates can be given by two vector arguments or by a single arguments x which is a times series, a two-column matrix, or a list containing components named x and y. y values must be monotone (ties are allowed). Missing values (NA) are allowed.

OPTIONAL ARGUMENTS:

n
approximate number of output points. This is ignored if newx is supplied.
xmin, xmax
range of output x values. This is ignored if newx is supplied.
newx
output values of x. Default values include all input values plus values equally spaced between each pair of neighboring input x values. Missing values (NA) are allowed.
boundary
vector of length 2, real values determining boundary conditions. If negative (the default), the L2 norm of the first derivative is minimized. For positive values see below.

VALUE:

list with vector components
x
vector, the input newx
y
vector, value of the spline function at those x values.

DETAILS:

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.

REFERENCES:

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.

SEE ALSO:

, , , , .

EXAMPLES:

x <- ppoints(10) 
y <- log(x) 
plot(x, y) 
lines(monotoneSpline(x, y))