This is basically using least square to estimate the coefficients of spline functions.
Then
and
We can use simple R functions lsfit to estimate the $\Phi$ as follows:
123456789101112131415
# define the rangeRng =c(1,18)age = growth$age
agefine =seq(1,18,len=501)# set up order 6 spline basis with 12 basis functions for# fitting the growth data so as to estimate accelerationnbasis =12;norder =6;heightbasis12 = create.bspline.basis(ageRng, nbasis, norder)# fit the data by least squaresbasismat = eval.basis(age, heightbasis12)heightmat = growth$hgtf
heightcoef = lsfit(basismat, heightmat, intercept=FALSE)$coef
# heightcoef is a 12 * 54 matrix. Each column represents the coefficients for 12 basis functions for each boy.
Or there is a function in the fda package: smooth.basis. This function takes three arguments, $t_j, y_j$ and $\Phi$. That is, the support of the responses, the responses and the bspline basis system. It returns a fd object and several other things.
temp =data.frame(a = rnorm(10),b =LETTERS[1:10])temp
a b
11.9106530 A
20.5568481 B
3-2.0955271 C
4-0.4132244 D
50.4280722 E
6-0.5981550F70.4110932 G
8-0.8469106 H
9-0.3415771I100.2930876 J
dput(temp)structure(list(a =c(1.91065303013136,0.556848072515929,-2.09552705843547,-0.413224404461701,0.428072223420949,-0.598155043699695,0.411093231611976,-0.846910593628984,-0.341577057278408,0.293087562336535), b =c("A","B","C","D","E","F","G","H","I","J")),.Names =c("a","b"), row.names =c(NA,-10L), class ="data.frame")
An object of fd combines the coefficients with the basis system. In the previous post, we learned that create.bspline.basis entable one create a system of bsplines. The object class is fdbasis.
add coefficients to the fdbasis to obtain a functional data object fd.
Use the function fd() in R.
1
tempfd = fd(coefmat,bspline_temp)
Note that adding coefficients in is different from evaluate a bspline system at a given time point $t$. Suppose $f(x)$ is approximated by a bspline system with basis functions denoted by $\phi_i(x)$. That is,
Thus, evaluating $f(t)$ means that given $t = t_0$ compute $f(t_0)$, which is essentially a vector. Each element in the vector stands for the basis function value when $t = t_0$, i.e., $\phi_i(t_0)$. On the other hand, supply coefficients into the bspline system amounts to given the value of $\beta_i$. Once the coefficients are given, one can evaluate the smoothing system as a single function given $t=t_0$ using R function eval.fd().
1234567891011121314151617181920
unitRng =c(0,1)bspl2 = create.bspline.basis(unitRng, norder=2)tstFn1 = fd(c(-1,2), bspl2)t0 =seq(0,1,by=0.2)eval.fd(t0,tstFn1) reps 1[1,]-1.0[2,]-0.4[3,]0.2[4,]0.8[5,]1.4[6,]2.0> eval.fd(t0,tstFn1,1)# evaluate the function data object tstFn1 first derivative. reps 1[1,]3[2,]3[3,]3[4,]3[5,]3[6,]0
Linear Differential Operator or Lfd Class
The notation $Lx$ refers to the application of a linear differential operator L to a function $x$. In general,
There are normally four relevant arguments that defines a bspline basis system.
rangeval: gives the range of the bspline functions
nbasis: the number of basis functions in total
norder: the order of the bspline, which equals one plus the degree. the default is set to be 4, i.e., cubic splines
breaks: the breaking points. It must satisfy that the first and last breaks are the boundary of the rangeval. For example, the code below specifies a bspline system with 13 basis functions. Each basis function is a cubic polynomial function.
In fact, one only needs to gives breaks and norder, then the function will know the nbasis, since nbasis = order + number of internal knots.
one property of bspline basis system is that the sum of B-spline basis function at any given time t sum up to 1.
evaluate bspline system at given time points
Once the bspline system is created, one might be interested in checking each basis function values at a given time t. This can be achieved by eval.basis function in R. It also computes derivatives when a third argument Lfdobj is given. In R, predict function can also do the same thing.
Markdown is a powerful and simple approach to document blog postings. It enables one to write in a plain text format and transfers them into clean, web-standard HTMLs.
Headings
Headings start with a # symbol. The largest one comes with one # and the second large one with 2 #.
12
# Markdown Syntax
## Headings
Paragraphs
Like latex, new paragraph is seperated with the previous one using a blank row in between.
This is another paragraph.
Bold and itshape
Bold on one word or serveral words together can be achieved by adding ** on two sides.
itshape is done by adding one * on each side of the word.