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 splines.

ibs(x, df = NULL, knots = NULL, degree = 3, intercept = FALSE,
Boundary.knots = range(x, na.rm = TRUE), ...)

## Arguments

x 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 can specify df rather than knots, then the function chooses "df - degree" (minus one if there is an intercept) knots at suitable quantiles of x (which will ignore missing values). The default, NULL, corresponds to no inner knots, i.e., "degree - intercept". The internal breakpoints that define the B-spline basis to be integrated. The default is NULL, which results in a basis for ordinary polynomial regression. Typical values are the mean or median for one knot, quantiles for more knots. See also Boundary.knots. Non-negative integer degree of the piecewise polynomial to be integrated. The default value is 3 for the integral of cubic B-splines. If TRUE, an intercept is included in the basis; Default is FALSE. Boundary points at which to anchor the B-spline basis to be integrated. By default, they are the range of the non-NA data. If both knots and Boundary.knots are supplied, the basis parameters do not depend on x. Data can extend beyond Boundary.knots. Optional arguments for future usage.

## Value

A matrix of dimension length(x) by 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.

## Details

It is an implementation of the close form integral of B-spline basis based on recursion relation. Internally, it calls bSpline and 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 x.

## References

De Boor, Carl. (1978). A practical guide to splines. Vol. 27. New York: Springer-Verlag.

predict.ibs for evaluation at given (new) values; deriv.ibs for derivative method. bSpline for B-splines; dbs for derivatives of B-splines;

## Examples

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))