create.bspline.basis | Language Reference for FDA Library
|
create.bspline.basis(rangeval=c(0, 1), nbasis=NULL, norder=4, breaks=NULL, dropind=NULL, quadvals=NULL, values=NULL)
c(0,1)
breaks[1] = rangeval[1]
and
breaks[nbreaks] = rangeval[2]
, where
nbreaks
is the
length of
breaks
. There must be at least 3 values in
breaks
.
There is a potential for inconsistency among arguments
nbasis
,
norder
, and
breaks
. It is resolved as follows:
If
breaks
is supplied,
nbreaks = length(breaks)
, and
nbasis = nbreaks + norder - 2
, no matter what value for
nbasis
is
supplied.
If
breaks
is not supplied, but
nbasis
is,
nbreaks = nbasis - norder + 2
,
and if this turns out to be less than 3, an error message results.
If neither
breaks
nor
nbasis
is supplied,
nbreaks
is set to 21.
quadvals
.
bspline
Spline functions are constructed by joining polynomials end-to-end at argument values called break points or knots. First, the interval is subdivided into a set of adjoining intervals separated the knots. Then a polynomial of order m and degree m-1 is defined for each interval. In order to make the resulting piece-wise polynomial smooth, two adjoining polynomials are constrained to have their values and all their derivatives up to order m-2 match at the point where they join.
Consider as an illustration the very common case where the order is 4 for all polynomials, so that degree of each polynomials is 3. That is, the polynomials are cubic. Then at each break point or knot, the values of adjacent polynomials must match, and so also for their first and second derivatives. Only their third derivatives will differ at the point of junction.
The number of degrees of freedom of a cubic spline function of this nature is calculated as follows. First, for the first interval, there are four degrees of freedom. Then, for each additional interval, the polynomial over that interval now has only one degree of freedom because of the requirement for matching values and derivatives. This works out to the following equation: The number of degrees of freedom is equal to the number of interior knots (that is, not counting the lower and upper limits) plus the order of the polynomials.
B-splines are a set of special spline functions that can be used to construct any such piece-wise polynomial by computing the appropriate linear combination. They derive their computational convience from the fact that any B-spline basis function is nonzero over at most m adjacent intervals. The number of basis functions is given by the rule above for the number of degrees of freedom.
The number of intervals controls the flexibility of the spline; the more knots, the more flexible the resulting spline will be. But the position of the knots also plays a role. Where do we position the knots? There is room for judgment here, but two considerations must be kept in mind: (1) you usually want at least one argument value between two adjacent knots, and (2) there should be more knots where the curve needs to have sharp curvatures such as a sharp peak or valley or an abrupt change of level, but only a few knots are required where the curve is changing very slowly.
# set up the b-spline basis for the lip data, using 23 basis functions, # order 4 (cubic), and equally spaced knots. # There will be 23 - 4 = 19 interior knots at 0.05, ..., 0.95 lipbasis <- create.bspline.basis(c(0,1), 23) # plot the basis functions plot(lipbasis)