as.fd {fda} | R Documentation |
Convert a spline object to class 'fd'
Description
Translate a spline object of another class into the
Functional Data (class fd
) format.
Usage
as.fd(x, ...)
## S3 method for class 'fdSmooth'
as.fd(x, ...)
## S3 method for class 'function'
as.fd(x, ...)
## S3 method for class 'smooth.spline'
as.fd(x, ...)
Arguments
x |
an object to be converted to class |
... |
optional arguments passed to specific methods, currently unused. |
Details
The behavior depends on the class
and nature of x
.
- as.fd.fdSmooth
extract the
fd
component- as.fd.function
-
Create an
fd
object from a function of the form created bysplinefun
. 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 bycreate.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 Wikipediaspline
article). 'periodic' splines do not use coincident boundary knots and are not currently supported infda
; instead,fda
uses finite Fourier bases for periodic phenomena. - as.fd.smooth.spline
-
Create an
fd
object from asmooth.spline
object.
Author(s)
Spencer Graves
References
Ramsay, James O., Hooker, Giles, and Graves, Spencer (2009), Functional data analysis with R and Matlab, Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2005), 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
https://en.wikipedia.org/wiki/Spline_(mathematics)
See Also
Examples
##
## 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)
fd_function <- splinefun(x2, y2)
fd. <- as.fd(fd_function)
x. <- seq(1, 7, .02)
fdx. <- fda::eval.fd(x., fd.)
# range(y2, fx., fdx.) generates an error 2012.04.22
rfdx <- range(fdx.)
oldpar <- par(no.readonly= TRUE)
plot(range(x2), range(y2, fdx., rfdx), type='n')
points(x2, y2)
lines(x., sin((x.-0.5)*pi), lty='dashed')
lines(x., fdx., 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)
if(!CRAN()) {
# 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.
}
##
## as.fd.smooth.spline ... this doesn't work (24 January 2024)
##
#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)
par(oldpar)