bsc {bspline} R Documentation

## Basis matrix and knot Jacobian for B-spline of order 0 (step function) and higher

### Description

This function is analogous but not equivalent to splines:bs() and splines2::bSpline(). It is also several times faster.

### Usage

bsc(x, xk, n = 3L, cjac = FALSE)


### Arguments

 x Numeric vector, abscissa points xk Numeric vector, knots n Integer scalar, polynomial order (3 by default) cjac Logical scalar, if TRUE makes to calculate Jacobian of basis vectors as function of knot positions (FALSE by default)

### Details

For n==0, step function is defined as constant on each interval [xk[i]; xk[i+1][, i.e. closed on the left and open on the right except for the last interval which is closed on the right too. The Jacobian for step function is considered 0 in every x point even if in points where x=xk, the derivative is not defined.
For n==1, Jacobian is discontinuous in such points so for these points we take the derivative from the right.

### Value

Numeric matrix (for cjac=FALSE), each column correspond to a B-spline calculated on x; or List (for cjac=TRUE) with components

mat

basis matrix of dimension nx x nw, where nx is the length of x and nw=nk-n-1 is the number of basis vectors

jac

array of dimension nx x (n+2) x nw where n+2 is the number of support knots for each basis vector

splines::bs(), splines2::bSpline()

### Examples

  x=seq(0, 5, length.out=101)
# cubic basis matrix
n=3
m=bsc(x, xk=c(rep(0, n+1), 1:4, rep(5, n+1)), n=n)
matplot(x, m, t="l")
stopifnot(all.equal.numeric(c(m), c(splines::bs(x, knots = 1:4, degree = n, intercept = TRUE))))


[Package bspline version 2.1 Index]