-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheval.basis.Rd
164 lines (147 loc) · 4.71 KB
/
eval.basis.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
\name{eval.basis}
\alias{eval.basis}
\alias{predict.basisfd}
\title{
Values of Basis Functions or their Derivatives
}
\description{
A set of basis functions are evaluated at a vector of argument values.
If a linear differential object is provided, the values are the
result of applying the the operator to each basis function.
}
\usage{
eval.basis(evalarg, basisobj, Lfdobj=0, returnMatrix=FALSE)
\method{predict}{basisfd}(object, newdata=NULL, Lfdobj=0,
returnMatrix=FALSE, ...)
}
\arguments{
\item{evalarg, newdata}{
a vector of argument values at which the basis functiona is to be
evaluated.
}
\item{basisobj}{
a basis object defining basis functions whose values
are to be computed.
}
\item{Lfdobj}{
either a nonnegative integer or a linear differential.
operator object.
}
\item{object}{
an object of class \code{basisfd}
}
\item{\dots}{
optional arguments for \code{predict}, not currently used
}
\item{returnMatrix}{
logical: If TRUE, a two-dimensional is returned using a
special class from the Matrix package.
}
}
\details{
If a linear differential operator object is supplied, the basis must
be such that the highest order derivative can be computed. If a
B-spline basis is used, for example, its order must be one larger than
the highest order of derivative required.
}
\value{
a matrix of basis function values with rows corresponding
to argument values and columns to basis functions.
\code{predict.basisfd} is a convenience wrapper for
\code{eval.basis}.
}
\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.
}
\seealso{
\code{\link{getbasismatrix}},
\code{\link{eval.fd}},
\code{\link{plot.basisfd}}
}
\examples{
##
## 1. B-splines
##
# The simplest basis currently available:
# a single step function
bspl1.1 <- create.bspline.basis(norder=1, breaks=0:1)
eval.bspl1.1 <- eval.basis(seq(0, 1, .2), bspl1.1)
# check
eval.bspl1.1. <- matrix(rep(1, 6), 6,
dimnames=list(NULL, 'bspl') )
\dontshow{stopifnot(}
all.equal(eval.bspl1.1, eval.bspl1.1.)
\dontshow{)}
# The second simplest basis:
# 2 step functions, [0, .5], [.5, 1]
bspl1.2 <- create.bspline.basis(norder=1, breaks=c(0,.5, 1))
eval.bspl1.2 <- eval.basis(seq(0, 1, .2), bspl1.2)
# Second order B-splines (degree 1: linear splines)
bspl2.3 <- create.bspline.basis(norder=2, breaks=c(0,.5, 1))
eval.bspl2.3 <- eval.basis(seq(0, 1, .1), bspl2.3)
# 3 bases: order 2 = degree 1 = linear
# (1) line from (0,1) down to (0.5, 0), 0 after
# (2) line from (0,0) up to (0.5, 1), then down to (1,0)
# (3) 0 to (0.5, 0) then up to (1,1).
##
## 2. Fourier
##
# The false Fourier series with 1 basis function
falseFourierBasis <- create.fourier.basis(nbasis=1)
eval.fFB <- eval.basis(seq(0, 1, .2), falseFourierBasis)
# Simplest real Fourier basis with 3 basis functions
fourier3 <- create.fourier.basis()
eval.fourier3 <- eval.basis(seq(0, 1, .2), fourier3)
# 3 basis functions on [0, 365]
fourier3.365 <- create.fourier.basis(c(0, 365))
eval.F3.365 <- eval.basis(day.5, fourier3.365)
oldpar <- par(no.readonly=TRUE)
matplot(eval.F3.365, type="l")
# The next simplest Fourier basis (5 basis functions)
fourier5 <- create.fourier.basis(nbasis=5)
eval.F5 <- eval.basis(seq(0, 1, .1), fourier5)
matplot(eval.F5, type="l")
# A more complicated example
dayrng <- c(0, 365)
nbasis <- 51
norder <- 6
weatherBasis <- create.fourier.basis(dayrng, nbasis)
basisMat <- eval.basis(day.5, weatherBasis)
matplot(basisMat[, 1:5], type="l")
##
## 3. predict.basisfd
##
basisMat. <- predict(weatherBasis, day.5)
\dontshow{stopifnot(}
all.equal(basisMat, basisMat.)
\dontshow{)}
##
## 4. Date and POSIXct
##
# Date
July4.1776 <- as.Date('1776-07-04')
Apr30.1789 <- as.Date('1789-04-30')
AmRev <- c(July4.1776, Apr30.1789)
BspRevolution <- create.bspline.basis(AmRev)
AmRevYears <- seq(July4.1776, Apr30.1789, length.out=14)
AmRevBases <- predict(BspRevolution, AmRevYears)
matplot(AmRevYears, AmRevBases, type='b')
# Image is correct, but
# matplot does not recogize the Date class of x
# POSIXct
AmRev.ct <- as.POSIXct1970(c('1776-07-04', '1789-04-30'))
BspRev.ct <- create.bspline.basis(AmRev.ct)
AmRevYrs.ct <- seq(AmRev.ct[1], AmRev.ct[2], length.out=14)
AmRevBas.ct <- predict(BspRev.ct, AmRevYrs.ct)
matplot(AmRevYrs.ct, AmRevBas.ct, type='b')
# Image is correct, but
# matplot does not recognize the POSIXct class of x
par(oldpar)
}
% docclass is function
\keyword{smooth}