Chapter 3 fdaWithRMat

create bspline basis functions

There are normally four relevant arguments that defines a bspline basis system.

  1. rangeval: gives the range of the bspline functions
  2. nbasis: the number of basis functions in total
  3. norder: the order of the bspline, which equals one plus the degree. the default is set to be 4, i.e., cubic splines
  4. 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.
  5. In fact, one only needs to gives breaks and norder, then the function will know the nbasis, since nbasis = order + number of internal knots.
1
bspline_temp = create.bspline.basis(rangeval = c(0,10), nbasis = 13,norder=4,breaks = 0:10)
  1. 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
eval.basis(evalarg=1:3,bspline_temp)
eval.basis(evalarg=1:3,bspline_temp)[,1:6]
     bspl4.1 bspl4.2   bspl4.3   bspl4.4   bspl4.5   bspl4.6
[1,]       0    0.25 0.5833333 0.1666667 0.0000000 0.0000000
[2,]       0    0.00 0.1666667 0.6666667 0.1666667 0.0000000
[3,]       0    0.00 0.0000000 0.1666667 0.6666667 0.1666667
rowSums(eval.basis(evalarg=1:3,bspline_temp))
[1] 1 1 1
eval.basis(evalarg=1:3,bspline_temp,Lfdobj=1)
     bspl4.1 bspl4.2 bspl4.3 bspl4.4 bspl4.5 bspl4.6 bspl4.7 bspl4.8
[1,]       0   -0.75    0.25     0.5     0.0     0.0       0       0
[2,]       0    0.00   -0.50     0.0     0.5     0.0       0       0
[3,]       0    0.00    0.00    -0.5     0.0     0.5       0       0
# using predict function
> predict(bspline_temp,1:3,1)
     bspl4.1 bspl4.2 bspl4.3 bspl4.4 bspl4.5 bspl4.6 bspl4.7 bspl4.8
[1,]       0   -0.75    0.25     0.5     0.0     0.0       0       0
[2,]       0    0.00   -0.50     0.0     0.5     0.0       0       0
[3,]       0    0.00    0.00    -0.5     0.0     0.5       0       0