| ibs {splines2} | R Documentation |
Generates basis matrix for integrals of B-splines.
ibs( x, df = NULL, knots = NULL, degree = 3, intercept = FALSE, Boundary.knots = NULL, ... )
x |
The predictor variable. Missing values are allowed and will be returned as they are. |
df |
Degree of freedom that equals to the column number of the returned
matrix. One can specify |
knots |
The internal breakpoints that define the splines. The default
is |
degree |
A nonnegative integer specifying the degree of the piecewise
polynomial. The default value is |
intercept |
If |
Boundary.knots |
Boundary points at which to anchor the splines. By
default, they are the range of |
... |
Optional arguments that are not used. |
The implementation is based on the close form recursion formula.
A numeric matrix of length(x) rows and df columns if
df is specified or length(knots) + degree +
as.integer(intercept) columns if knots are specified instead.
Attributes that correspond to the arguments specified are returned
mainly for other functions in this package.
De Boor, Carl. (1978). A practical guide to splines. Vol. 27. New York: Springer-Verlag.
bSpline for B-splines;
dbs for derivatives of B-splines;
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) ## get the corresponding B-splines by bSpline() bsMat0 <- bSpline(x, knots = knots, degree = 1, intercept = TRUE) ## or by the deriv() method bsMat <- deriv(ibsMat) stopifnot(all.equal(bsMat0, bsMat, check.attributes = FALSE)) ## plot B-spline basis with their corresponding integrals op <- 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") ## reset to previous plotting settings par(op)