bsc {bspline} | R Documentation |
This function is analogous but not equivalent to splines:bs()
and splines2::bSpline()
.
It is also several times faster.
bsc(x, xk, n = 3L, cjac = FALSE)
x |
Numeric vector, abscissa points |
xk |
Numeric vector, knots |
n |
Integer scalar, polynomial order (3 by default) |
cjac |
Logical scalar, if |
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.
Numeric matrix (for cjac=FALSE), each column correspond to a B-spline calculated on x; or List (for cjac=TRUE) with components
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
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()
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))))