Description Usage Arguments Details Value Author(s) References See Also Examples
Translate a spline object of another class into DierckxSpline (class
dierckx
) format.
1 2 3 | as.dierckx(x)
## S3 method for class 'fd'
as.dierckx(x)
|
x |
an object to be converted to class |
The behavior depends on the class
and nature of x
. In
particular, the DierckxSpline
package only supports splines of
order between 2 and 6, degree between 1 and 5, for linear through
quintic splines. Other packages, e.g., fda
support splines
over a wider range and non-spline basis functions such as finite
Fourier series. When these are encountered, as.dierckx
throws
an error.
as.dierckx.fd
The following describes how the components of a dierckx
object are constructed from a spline object of a different class:
xRestored from the knots.
y Restored from spline predictions at the restored values of knot locations 'x'.
wlost. Restored as rep(1, length(x)).
from, tofd[["basis"]][["rangeval"]]
k coded indirectly as fd[["basis"]][["nbasis"]] - length(fd[["basis"]][["params"]]) - 1.
slost, restored as 0.
nestlost, restored as length(x) + k + 1
n coded indirectly as 2*fd[["basis"]][["nbasis"]] - length(fd[["basis"]][["params"]]).
knots The end knots are stored (unreplicated) in fd[["basis"]][["rangeval"]], while the interior knots are stored in fd[["basis"]][["params"]].
fplost. Restored as 0.
wrk, lwrk, iwrk lost. Restore by refitting to the knots.
ierlost. Restored as 0.
messagelost. Restored as character(0).
g stored indirectly as length(fd[["basis"]][["params"]]).
methodlost. Restored as "ss".
periodic 'dierckx2fd' only translates 'dierckx' objects with coincident boundary knots. Therefore, 'periodic' is restored as FALSE.
routinelost. Restored as 'curfit.default'.
xlabfd[["fdnames"]][["args"]]
ylabfd[["fdnames"]][["funs"]]
as.fd.dierckx
converts an object of class 'dierckx' into one of
class fd
.
Spencer Graves
Dierckx, P. (1991) Curve and Surface Fitting with Splines, Oxford Science Publications.
Ramsay, James O., and Silverman, Bernard W. (2006), Functional Data Analysis, 2nd ed., Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2002), Applied Functional Data Analysis, Springer, New York.
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 35 36 37 38 39 40 41 42 43 | x <- 0:24
y <- c(1.0,1.0,1.4,1.1,1.0,1.0,4.0,9.0,13.0,
13.4,12.8,13.1,13.0,14.0,13.0,13.5,
10.0,2.0,3.0,2.5,2.5,2.5,3.0,4.0,3.5)
curfit.xy <- curfit(x, y, s=0)
if(require(fda)) {
# as.fd was not exported; now it is,
# but I need fda:::as.fd temporarily
curfit.fd <- fda:::as.fd(curfit.xy)
plot(curfit.fd) # as an 'fd' object
points(x, y) # Curve goes through the points.
x. <- seq(0, 24, length=241)
pred.y <- predict(curfit.xy, x.)
lines(x., pred.y, lty="dashed", lwd=3, col="blue")
# dierckx and fd objects match.
all.equal(knots(curfit.xy, FALSE), knots(curfit.fd, FALSE))
all.equal(coef(curfit.xy), as.vector(coef(curfit.fd)))
curfit2 <- as.dierckx(curfit.fd)
pred.y2 <- predict(curfit2, x.)
sum(abs(pred.y-pred.y2))/(sum(abs(pred.y)+abs(pred.y2))/2)
# 1.3e-7
all.equal(knots(curfit.xy, FALSE), knots(curfit2, FALSE))
# TRUE
all.equal(coef(curfit.xy), coef(curfit2))
# "Mean relative difference: 4.5e-7
preserved <- c("from", "to", "n", "g", "periodic", "xlim","ylim")
all.equal(curfit.xy[preserved], curfit2[preserved])
# TRUE
# Other components are NOT preserved in translation
# and so can NOT be restored.
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.