splineDesign
Design Matrix for Bsplines
Evaluate the design matrix for the Bsplines defined by knots
at the values in x
.
 Keywords
 models
Usage
splineDesign(knots, x, ord = 4, derivs, outer.ok = FALSE, sparse = FALSE)
spline.des (knots, x, ord = 4, derivs, outer.ok = FALSE, sparse = FALSE)
Arguments
 knots
 a numeric vector of knot positions (which will be sorted increasingly if needed).
 x
 a numeric vector of values at which to evaluate the Bspline
functions or derivatives. Unless
outer.ok
is true, the values inx
must be between the “inner” knotsknots[ord]
andknots[ length(knots)  (ord1)]
.  ord
 a positive integer giving the order of the spline function. This is the number of coefficients in each piecewise polynomial segment, thus a cubic spline has order 4. Defaults to 4.
 derivs
 an integer vector with values between
0
andord  1
, conceptually recycled to the length ofx
. The derivative of the given order is evaluated at thex
positions. Defaults to zero (or a vector of zeroes of the same length asx
).  outer.ok
 logical indicating if
x
should be allowed outside the inner knots, see thex
argument.  sparse
 logical indicating if the result should inherit from class
"sparseMatrix"
(from package \href{https://CRAN.Rproject.org/package=#1}{\pkg{#1}}MatrixMatrix).
Value

A matrix with
length(x)
rows and length(knots)  ord
columns. The i'th row of the matrix contains the coefficients of the
Bsplines (or the indicated derivative of the Bsplines) defined by
the knot
vector and evaluated at the i'th value of x
.
Each Bspline is defined by a set of ord
successive knots so
the total number of Bsplines is length(knots)  ord
.
Note
The older spline.des
function takes the same arguments but
returns a list with several components including knots
,
ord
, derivs
, and design
. The design
component is the same as the value of the splineDesign
function.
Examples
library(splines)
require(graphics)
splineDesign(knots = 1:10, x = 4:7)
splineDesign(knots = 1:10, x = 4:7, deriv = 1)
## visualize band structure
Matrix::drop0(zapsmall(6*splineDesign(knots = 1:40, x = 4:37, sparse = TRUE)))
knots < c(1,1.8,3:5,6.5,7,8.1,9.2,10) # 10 => 104 = 6 Basis splines
x < seq(min(knots)1, max(knots)+1, length.out = 501)
bb < splineDesign(knots, x = x, outer.ok = TRUE)
plot(range(x), c(0,1), type = "n", xlab = "x", ylab = "",
main = "Bsplines  sum to 1 inside inner knots")
mtext(expression(B[j](x) *" and "* sum(B[j](x), j == 1, 6)), adj = 0)
abline(v = knots, lty = 3, col = "light gray")
abline(v = knots[c(4,length(knots)3)], lty = 3, col = "gray10")
lines(x, rowSums(bb), col = "gray", lwd = 2)
matlines(x, bb, ylim = c(0,1), lty = 1)
Community examples
Looks like there are no examples yet.