Description Usage Arguments Details Value Author(s) References See Also Examples
Translate a spline object of another class into the Functional Data
(class fd
) format.
1 2 3 4 5 6 7 |
x |
an object to be converted to class |
... |
optional arguments passed to specific methods, currently unused. |
The behavior depends on the class
and nature of x
.
as.fd.fdSmoothextract the fd
component
as.fd.dierckx
The 'fda' package (as of version 2.0.0) supports B-splines with
coincident boundary knots. For periodic phenomena, the
DierckxSpline
packages uses periodic spines, while
fda
recommends finite Fourier series. Accordingly,
as.fd.dierckx
if x[["periodic"]] is TRUE.
The following describes how the components of a dierckx
object are handled by as.dierckx(as.fd(x)):
xlost. Restored from the knots.
y lost. Restored from spline predictions at the restored values of '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).
gstored 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.function
Create an fd
object from a function of the form created by
splinefun
. This will translate method = 'fmn' and
'natural' but not 'periodic': 'fmn' splines are isomorphic to
standard B-splines with coincident boundary knots, which is the
basis produced by create.bspline.basis
. 'natural' splines
occupy a subspace of this space, with the restriction that the
second derivative at the end points is zero (as noted in the
Wikipedia spline
article). 'periodic' splines do not use
coindicent boundary knots and are not currently supported in
fda
; instead, fda
uses finite Fourier bases for
periodic phenomena.
as.fd.smooth.spline
Create an fd
object from a smooth.spline
object.
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.
spline
entry in Wikipedia
http://en.wikipedia.org/wiki/Spline_(mathematics)
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | ##
## as.fd.fdSmooth
##
girlGrowthSm <- with(growth, smooth.basisPar(argvals=age, y=hgtf,
lambda=0.1))
girlGrowth.fd <- as.fd(girlGrowthSm)
##
## as.fd.function(splinefun(...), ...)
##
x2 <- 1:7
y2 <- sin((x2-0.5)*pi)
f <- splinefun(x2, y2)
fd. <- as.fd(f)
x. <- seq(1, 7, .02)
fx. <- f(x.)
fdx. <- eval.fd(x., fd.)
# range(y2, fx., fdx.) generates an error 2012.04.22
rfdx <- range(fdx.)
plot(range(x2), range(y2, fx., rfdx), type='n')
points(x2, y2)
lines(x., sin((x.-0.5)*pi), lty='dashed')
lines(x., f(x.), col='blue')
lines(x., eval.fd(x., fd.), col='red', lwd=3, lty='dashed')
# splinefun and as.fd(splineful(...)) are close
# but quite different from the actual function
# apart from the actual 7 points fitted,
# which are fitted exactly
# ... and there is no information in the data
# to support a better fit!
# Translate also a natural spline
fn <- splinefun(x2, y2, method='natural')
fn. <- as.fd(fn)
lines(x., fn(x.), lty='dotted', col='blue')
lines(x., eval.fd(x., fn.), col='green', lty='dotted', lwd=3)
## Not run:
# Will NOT translate a periodic spline
fp <- splinefun(x, y, method='periodic')
as.fd(fp)
#Error in as.fd.function(fp) :
# x (fp) uses periodic B-splines, and as.fd is programmed
# to translate only B-splines with coincident boundary knots.
## End(Not run)
##
## as.fd.smooth.spline
##
cars.spl <- with(cars, smooth.spline(speed, dist))
cars.fd <- as.fd(cars.spl)
plot(dist~speed, cars)
lines(cars.spl)
sp. <- with(cars, seq(min(speed), max(speed), len=101))
d. <- eval.fd(sp., cars.fd)
lines(sp., d., lty=2, col='red', lwd=3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.