-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathas.fd.Rd
139 lines (125 loc) · 3.92 KB
/
as.fd.Rd
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
\name{as.fd}
\alias{as.fd}
\alias{as.fd.fdSmooth}
\alias{as.fd.function}
\alias{as.fd.smooth.spline}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Convert a spline object to class 'fd'
}
\description{
Translate a spline object of another class into the
Functional Data (class \code{fd}) format.
}
\usage{
as.fd(x, ...)
\method{as.fd}{fdSmooth}(x, ...)
\method{as.fd}{function}(x, ...)
\method{as.fd}{smooth.spline}(x, ...)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{x}{
an object to be converted to class \code{fd}.
}
\item{\dots}{
optional arguments passed to specific methods, currently
unused.
}
}
\details{
The behavior depends on the \code{class} and nature of \code{x}.
\describe{
\item{as.fd.fdSmooth}{extract the \code{fd} component}
\item{as.fd.function}{
Create an \code{fd} object from a function of the form
created by \code{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
\code{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 \code{spline} article). 'periodic' splines
do not use coincident boundary knots and are not
currently supported in \code{fda}; instead, \code{fda}
uses finite Fourier bases for periodic phenomena.
}
\item{as.fd.smooth.spline}{
Create an \code{fd} object from a \code{smooth.spline}
object.
}
}
}
\references{
Ramsay, James O., Hooker, Giles, and Graves, Spencer (2009),
\emph{Functional data analysis with R and Matlab}, Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2005),
\emph{Functional Data Analysis, 2nd ed.}, Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2002),
\emph{Applied Functional Data Analysis}, Springer, New York.
\code{spline} entry in \emph{Wikipedia}
\url{https://en.wikipedia.org/wiki/Spline_(mathematics)}
}
\author{Spencer Graves}
\seealso{
\code{\link{fd}}
\code{\link{splinefun}}
}
\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)
}
\keyword{smooth}
\keyword{manip}