This function generates the integral of B-spline basis matrix
for a polynomial spline. The arguments are exactly the same with function
bs in package
ibs(x, df = NULL, knots = NULL, degree = 3, intercept = FALSE, Boundary.knots = range(x, na.rm = TRUE), ...)
The predictor variable. Missing values are allowed and will be returned as they were.
Degrees of freedom of the B-spline basis to be integrated. One
The internal breakpoints that define the B-spline basis to be
integrated. The default is
Non-negative integer degree of the piecewise polynomial to be integrated. The default value is 3 for the integral of cubic B-splines.
Boundary points at which to anchor the B-spline basis
to be integrated. By default, they are the range of the non-
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.
It is an implementation of the close form integral of B-spline basis based
on recursion relation. Internally, it calls
generates a basis matrix for representing the family of piecewise
polynomials and their corresponding integrals with the specified interior
knots and degree, evaluated at the values 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, 0.9) ibsMat <- ibs(x, knots = knots, degree = 1, intercept = TRUE) ## the B-spline bases integrated by function bSpline (same arguments) bsMat0 <- bSpline(x, knots = knots, degree = 1, intercept = TRUE) ## or by function deriv (recommended) that directly extracts the existing ## result from the attribute of ibsMat and thus is much more efficient. bsMat <- deriv(ibsMat) stopifnot(all.equal(bsMat0, bsMat, check.attributes = FALSE)) # equivalent ## plot B-spline basis with their corresponding integrals library(graphics) par(mfrow = c(1, 2)) matplot(x, bsMat, type = "l", ylab = "B-spline basis") abline(v = knots, lty = 2, col = "gray") matplot(x, ibsMat, type = "l", ylab = "Integral of B-spline basis")abline(v = knots, lty = 2, col = "gray")par(mfrow = c(1, 1))