View source: R/vsmooth.spline.q
vsmooth.spline | R Documentation |
Fits a vector cubic smoothing spline.
vsmooth.spline(x, y, w = NULL, df = rep(5, M), spar = NULL,
i.constraint = diag(M),
x.constraint = diag(M),
constraints = list("(Intercepts)" = i.constraint,
x = x.constraint),
all.knots = FALSE, var.arg = FALSE, scale.w = TRUE,
nk = NULL, control.spar = list())
x |
A vector, matrix or a list.
If a list, the |
y |
A vector, matrix or a list.
If a list, the |
w |
The weight matrices or the number of observations.
If the weight matrices, then this must be
a |
df |
Numerical vector containing the degrees of
freedom for each component function (smooth).
If necessary, the vector is recycled to have length equal
to the number of component functions to be estimated
( |
spar |
Numerical vector containing the non-negative smoothing
parameters for each component function (smooth).
If necessary, the vector is recycled to have length equal
to the number of component functions to be estimated
( |
all.knots |
Logical. If |
i.constraint |
A |
x.constraint |
A |
constraints |
An alternative to specifying |
var.arg |
Logical: return the pointwise variances of the fit? Currently, this corresponds only to the nonlinear part of the fit, and may be wrong. |
scale.w |
Logical.
By default, the weights |
nk |
Number of knots.
If used, this argument overrides |
control.spar |
See |
The algorithm implemented is detailed in Yee (2000).
It involves decomposing the component functions
into a linear and
nonlinear part, and using B-splines.
The cost of the computation is O(n M^3)
.
The argument spar
contains scaled
smoothing parameters.
An object of class "vsmooth.spline"
(see vsmooth.spline-class
).
See vgam
for information about an important bug.
This function is quite similar
to smooth.spline
but offers less functionality.
For example, cross validation is not implemented here.
For M = 1
, the results will be generally different,
mainly due to the different way the knots are selected.
The vector cubic smoothing spline which s()
represents is
computationally demanding for large M
.
The cost is approximately O(n M^3)
where
n
is the number of unique abscissae.
Yet to be done: return the unscaled smoothing parameters.
Thomas W. Yee
Yee, T. W. (2000). Vector Splines and Other Vector Smoothers. Pages 529–534. In: Bethlehem, J. G. and van der Heijde, P. G. M. Proceedings in Computational Statistics COMPSTAT 2000. Heidelberg: Physica-Verlag.
vsmooth.spline-class
,
plot.vsmooth.spline
,
predict.vsmooth.spline
,
iam
,
sm.os
,
s
,
smooth.spline
.
nn <- 20; x <- 2 + 5*(nn:1)/nn
x[2:4] <- x[5:7] # Allow duplication
y1 <- sin(x) + rnorm(nn, sd = 0.13)
y2 <- cos(x) + rnorm(nn, sd = 0.13)
y3 <- 1 + sin(x) + rnorm(nn, sd = 0.13) # For constraints
y <- cbind(y1, y2, y3)
ww <- cbind(rep(3, nn), 4, (1:nn)/nn)
(fit <- vsmooth.spline(x, y, w = ww, df = 5))
## Not run:
plot(fit) # The 1st & 3rd functions dont differ by a constant
## End(Not run)
mat <- matrix(c(1,0,1, 0,1,0), 3, 2)
(fit2 <- vsmooth.spline(x, y, w = ww, df = 5, i.constr = mat,
x.constr = mat))
# The 1st and 3rd functions do differ by a constant:
mycols <- c("orange", "blue", "orange")
## Not run: plot(fit2, lcol = mycols, pcol = mycols, las = 1)
p <- predict(fit, x = model.matrix(fit, type = "lm"), deriv = 0)
max(abs(depvar(fit) - with(p, y))) # Should be 0
par(mfrow = c(3, 1))
ux <- seq(1, 8, len = 100)
for (dd in 1:3) {
pp <- predict(fit, x = ux, deriv = dd)
## Not run:
with(pp, matplot(x, y, type = "l", main = paste("deriv =", dd),
lwd = 2, ylab = "", cex.axis = 1.5,
cex.lab = 1.5, cex.main = 1.5))
## End(Not run)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.