concon {DierckxSpline}R Documentation

Curve fitting with convexity constraints

Description

General curve fitting with splines with convexity constraints. Wrapper for the Fortran function CONCON.

Usage

concon(x, ...)
## Default S3 method:
concon(x, y = NULL, w = NULL, v = 0, s = 0, ...)

Arguments

x A data.frame, matrix, or numeric vector. See details.
y Optional numeric vector. See details.
w Optional vector of weights
v Convexity constraints. See details.
s Smoothing parameter
... Additional arguments used only in update.concon. Otherwise, ignored.

Details

As with smooth.spline, the x vector should contain at least four distinct values. Distinct here means ``distinct after rounding to 6 significant digits'', i.e., x will be transformed to unique(sort(signif(x, 6))), and y, w, and v are pooled accordingly.

For the default method, arguments x and y are supplied to xy.coords to determine abscissa and ordinate values. The actual function used is DierckxSpline:::xyw.coords which is not exported in the NAMESPACE.

concon determines a smooth cubic spline approximation s(x). See chapters 1 and 3 in the reference for definition of symbols.

The vector v should be the same length as x. v[i] must be set to 1 if s(x) must be locally concave at x[i], to -1 if s(x) must be locally convex at x[i] and to 0 if no convexity constraint is imposed at x[i]. If all v are 0 (no consraints) an error is thrown suggesting the use of curfit instead.

Value

An object of class dierckx with the following components:

iopt method used
m length of x
x abscissa values
y ordinate values
w input weights
s input smoothing parameter
nest Estimated number of knots
n Actual number of knots
knots Knot locations. Do NOT modify before call to update.dierckx
g Number of interior knots
coef b-Spline coefficients. Use coef.dierckx to extract.
fp sum of squares residuals. Use deviance.dierckx to extract.
wrk Work space. Do NOT modify before call to update.dierckx
lwrk Length of wrk. Do NOT modify before call to update.dierckx
iwrk Integer work space. Do NOT modify before call to update.dierckx
kwrk Length of iwrk. Do NOT modify before call to update.dierckx
bind Indicates the knots where s''(x)=0. Do NOT modify before call to update.dierckx
sx Indicates the knots where s''(x)=0. Do NOT modify before call to update.dierckx
ier Error code. Should always be zero.
method input method value
k Always 3 (cubic spline)
periodic Always FALSE
routine Always 'concon.default'
xlab The x-label determined from deparse(substitute(x)).
ylab The y-label determined from deparse(substitute(y)).

Author(s)

Sundar Dorai-Raj

References

Dierckx, P. (1991) Curve and Surface Fitting with Splines, Oxford Science Publications.

See Also

curfit, spline, smooth.spline

Examples

data(moisture)
f1 <- with(moisture, concon(x, y, w, v, s = 0.2))
f2 <- update(f1, s = 0.04)
f3 <- update(f1, s = 0.0002)
g1 <- with(moisture, curfit(x, y, w, knots = knots(f1, interior=FALSE)))
#must include end knots, via interior = FALSE 
g2 <- update(g1, knots = knots(f2, FALSE))
g3 <- update(g1, knots = knots(f3, FALSE))

newx <- with(moisture, seq(min(x), max(x), length = 100))
method <- c("Convexity Constrained", "Unconstrained Least Squares")
group <- c("0 interior knots", "1 interior knot", "3 interior knots")
out <- data.frame(x = rep(newx, times = 6),
         y = c(predict(f1, newx), predict(f2, newx),
               predict(f3, newx), predict(g1, newx),
               predict(g2, newx), predict(g3, newx)),
         group = rep(group, each = 100, times = 2),
         method = rep(method, each = 3 * 100))

library(lattice)
xyplot(y ~ x | method, out, groups = group, panel = function(...) {
         panel.superpose(...)
         panel.xyplot(moisture$x, moisture$y,
                      col = "#800000", pch = 16, cex = 1.2)
       },
       xlim = c(-1, 11), xlab = "", ylab = "", layout = c(1, 2),
       as.table = TRUE, scales = list(cex = 1.2), 
       par.strip.text = list(cex = 1.5), type = "l", lwd = 3,
       key = list(space = "top", cex = 1.2, columns = 3,
         text = list(levels(out$group)),
         lines = list(lwd = 3, col = trellis.par.get("superpose.line")$col[1:3])))

[Package DierckxSpline version 1.0-9 Index]