| bSpline {splines2} | R Documentation |
Generates the B-spline basis matrix representing the family of piecewise
polynomials with the specified interior knots and degree, evaluated at the
values of x.
bSpline( x, df = NULL, knots = NULL, degree = 3L, 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 returned
matrix. One can specify |
knots |
The internal breakpoints that define the spline. The default
is |
degree |
A non-negative integer specifying the degree of the piecewise polynomial. The default value is 3 for cubic splines. Zero degree is allowed for piece-wise constant bases. |
intercept |
If |
Boundary.knots |
Boundary points at which to anchor the spline basis.
By default, they are the range of the non- |
... |
Optional arguments that are not used. |
This function extends the bs() function in splines package for
B-spline basis by allowing piecewise constant (left-closed and right-open
except on the right boundary) spline basis with zero degree.
A numeric matrix with 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 for
usage of other functions in this package.
dbs for derivatives of B-splines;
ibs for integrals of B-splines;
library(splines2) x <- seq.int(0, 1, 0.01) knots <- c(0.3, 0.5, 0.6) ## cubic B-splines bsMat <- bSpline(x, knots = knots, degree = 3, intercept = TRUE) par(mar = c(2.5, 2.5, 0.2, 0.1), mgp = c(1.5, 0.5, 0)) matplot(x, bsMat, type = "l", ylab = "Cubic B-spline Bases") abline(v = knots, lty = 2, col = "gray") ## the first derivaitves d1Mat <- deriv(bsMat) ## the second derivaitves d2Mat <- deriv(bsMat, 2) ## evaluate at new values predict(bsMat, c(0.125, 0.801))