This function produces the derivative of given order of B-splines. It is an implementation of the close form derivative of B-spline basis based on recursion relation. At knots, the derivative is defined to be the right derivative.
dbs(x, derivs = 1L, df = NULL, knots = NULL, degree = 3L, intercept = FALSE, Boundary.knots = range(x, na.rm = TRUE), ...)
The predictor variable. Missing values are allowed and will be kept and returned as they were.
A positive integer specifying the order of derivative. By
default, it is
Degrees of freedom of the B-spline basis to be differentiated.
One can specify
The internal breakpoints that define the B-spline basis to be
differentiated. The default is
Non-negative integer degree of the piecewise polynomial to be differentiated. The default value is 3 for the integral of cubic B-splines.
Boundary points at which to anchor the B-spline basis
to be differentiated. By default, they are the range of the
Optional arguments for future usage.
A matrix of dimension
df = degree + length(knots) (plus on if intercept is included).
Attributes that correspond to the arguments specified are returned
for usage of other functions in this package.
The function is similar with
it provides a more user-friendly interface, a more considerate
handling. Internally, it calls
bSpline and generates a basis
matrix for representing the family of piecewise polynomials and their
corresponding derivative with the specified interior knots and degree,
evaluated at the values of
x. The function
splines package can also be used to calculate derivative of
De Boor, Carl. (1978). A practical guide to splines. Vol. 27. New York: Springer-Verlag.
library(splines2) x <- seq.int(0, 1, 0.01) knots <- c(0.2, 0.4, 0.7) ## the second derivative of cubic B-splines with three internal knots dMat <- dbs(x, derivs = 2L, knots = knots, intercept = TRUE) ## compare with the results from splineDesign ord <- attr(dMat, "degree") + 1L bKnots <- attr(dMat, "Boundary.knots") aKnots <- c(rep(bKnots[1L], ord), knots, rep(bKnots[2L], ord)) res <- splines::splineDesign(aKnots, x = x, derivs = 2L) stopifnot(all.equal(res, dMat, check.attributes = FALSE))