This function generates the B-spline basis matrix for a polynomial spline.
bSpline(x, 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 returned as they were.
Degrees of freedom. 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". If knots
was
specified, df
specified will be ignored.
The internal breakpoints that define the spline. 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. The
default value is 3 for cubic splines. Zero degree is allowed for this
function, which is the only difference compared with
bs
in package splines
.
If TRUE
, an intercept is included in the basis;
Default is FALSE
.
Boundary points at which to anchor the B-spline basis.
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.
A matrix of dimension length(x)
by
df = degree + length(knots)
(plus one if intercept is included).
Attributes that correspond to the arguments specified are returned
for usage of other functions in this package.
It is an augmented function of bs
in package
splines
for B-spline basis that allows piecewise constant (close on
the left, open on the right) spline basis with zero degree. When the
argument degree
is greater than zero, it internally calls
bs
and generates a basis matrix for representing the
family of piecewise polynomials with the specified interior knots and
degree, evaluated at the values of x
. The function has the same
arguments with bs
for ease usage.
predict.bSpline2
for evaluation at given (new) values;
dbs
, deriv.bSpline2
for derivatives;
ibs
for integral of B-splines;
mSpline
for M-splines;
iSpline
for I-splines;
cSpline
for C-splines.
# NOT RUN { library(splines2) x <- seq.int(0, 1, 0.01) knots <- c(0.3, 0.5, 0.6) bsMat <- bSpline(x, knots = knots, degree = 0, intercept = TRUE) library(graphics) matplot(x, bsMat, type = "l", ylab = "Piecewise constant B-spline bases") abline(v = knots, lty = 2, col = "gray") # }
Run the code above in your browser using DataCamp Workspace