Description Usage Arguments Details Value Author(s) References See Also Examples
General curve fitting with splines with convexity constraints. Wrapper for the Fortran function CONCON.
1 2 3 |
x |
A |
y |
Optional numeric vector. See details. |
w |
Optional vector of weights |
v |
Convexity constraints. See details. |
s |
Smoothing parameter |
... |
Additional arguments used only in
|
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.
An object of class dierckx
with the following components:
iopt |
method used |
m |
length of |
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
|
g |
Number of interior knots |
coef |
b-Spline coefficients. Use |
fp |
sum of squares residuals. Use |
wrk |
Work space. Do NOT modify before call to
|
lwrk |
Length of |
iwrk |
Integer work space. Do NOT modify before call to
|
kwrk |
Length of |
bind |
Indicates the knots where |
sx |
Indicates the knots where |
ier |
Error code. Should always be zero. |
method |
input |
k |
Always 3 (cubic spline) |
periodic |
Always |
routine |
Always 'concon.default' |
xlab |
The x-label determined from |
ylab |
The y-label determined from |
Sundar Dorai-Raj
Dierckx, P. (1991) Curve and Surface Fitting with Splines, Oxford Science Publications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | data(moisture)
## Not run:
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])))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.