| mSpline {splines2} | R Documentation |
Generates the basis matrix of the regression spline called M-spline or the
corresponding derivatives of given order. For monotone regression,
iSpline should be used instead of M-splines.
mSpline( x, df = NULL, knots = NULL, degree = 3L, intercept = FALSE, Boundary.knots = NULL, derivs = 0L, ... )
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- |
derivs |
A non-negative integer specifying the order of derivatives of
M-splines. The default value is |
... |
Optional arguments that are not used. |
It is an implementation of the close form M-spline basis based on the recursion formula given by Ramsay (1988).
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.
Ramsay, J. O. (1988). Monotone regression splines in action. Statistical science, 3(4), 425–441.
bSpline for B-splines;
iSpline for I-splines;
cSpline for C-splines.
library(splines2)
## Example given in the reference paper by Ramsay (1988)
x <- seq.int(0, 1, 0.01)
knots <- c(0.3, 0.5, 0.6)
msMat <- mSpline(x, knots = knots, degree = 2, intercept = TRUE)
par(mar = c(2.5, 2.5, 0.2, 0.1), mgp = c(1.5, 0.5, 0))
matplot(x, msMat, type = "l", ylab = "y")
abline(v = knots, lty = 2, col = "gray")
## derivatives of M-splines
dmsMat <- mSpline(x, knots = knots, degree = 2,
intercept = TRUE, derivs = 1)
## or using the deriv method
dmsMat1 <- deriv(msMat)
stopifnot(all.equal(dmsMat, dmsMat1, check.attributes = FALSE))