spliunes | R Documentation |
Spline basis expansions of a continuous variable.
BsplineBasis(x, knots = NULL, numknots = 3)
MsplineBasis(x, knots = NULL, numknots = 3)
IsplineBasis(x, knots = NULL, numknots = 3)
## S3 method for class 'SplineBasis'
knots(Fn, ...)
x |
A numeric vector to be expanded. |
knots |
A numeric vector of knots defining the expansion. The
smallest and largest elements in |
numknots |
If the knot vector is |
Fn |
A spline basis matrix. |
... |
Unused, but required to match the signature of the
|
B-splines are the basis most commonly used for additive regression models.
M-splines are an alternative to B-splines, but are rarely used.
I-splines are integrated M-splines. These are monotonic functions, which is useful in monotonic regression problems. If all regression coefficients are positive then the resulting function is nondecreasing.
XsplineBasis
returns a matrix formed by the spline basis
expansion of x
.
knots(Fn)
returns the knots
attribute of Fn
,
which might be useful in a second call to the basis expansion
function.
Steven L. Scott
Bsplines are described in deBoor (2001), "A Practical Guide to Splines". Springer.
Msplines and Isplines are reviewed by Ramsay (1988), Statistical Science pp. 425-461.
# Plot the B-spline basis for x with knots determined by 3 quantiles.
x <- sort(rnorm(1000))
basis <- BsplineBasis(x, numknots=3)
par(mfrow=c(2,3))
for(i in 1:5) plot(x, basis[, i], type="l")
# Plot the I-spline basis for x with the same knots.
basis <- IsplineBasis(x, numknots=3)
par(mfrow=c(2,3))
for(i in 1:5) plot(x, basis[, i], type="l")
# Bring you own knots...
basis <- BsplineBasis(x, knots = quantile(x, c(.2, .5, .8, .9)))
par(mfrow=c(2,3))
for(i in 1:6) plot(x, basis[, i], type="l")
knots(basis)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.