This function generates the monotone regression spline (or simply called M-spline) basis matrix for a polynomial spline or its derivatives of given order.
mSpline(x, df = NULL, knots = NULL, degree = 3L, intercept = FALSE, Boundary.knots = range(x, na.rm = TRUE), derivs = 0L, ...)
x | The predictor variable. Missing values are allowed and will be returned as they were. |
---|---|
df | Degrees of freedom. One can specify |
knots | The internal breakpoints that define the spline. The default
is |
degree | Non-negative integer degree of the piecewise polynomial. The default value is 3 for cubic splines. Zero degree is allowed for piecewise constant basis. |
intercept | If |
Boundary.knots | Boundary points at which to anchor the M-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 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 implementation of the close form M-spline basis based on
relationship between M-spline basis and B-spline basis. In fact, M-spline
basis is a rescaled version of B-spline basis. Internally, it calls function
bSpline
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
.
Ramsay, J. O. (1988). Monotone regression splines in action. Statistical science, 3(4), 425--441.
predict.mSpline
for evaluation at given (new) values;
deriv.mSpline
for derivative method;
bSpline
for B-splines;
iSpline
for I-splines;
cSpline
for C-splines.
## Example given in the reference paper by Ramsay (1988) library(splines2) x <- seq.int(0, 1, 0.01) knots <- c(0.3, 0.5, 0.6) msMat <- mSpline(x, knots = knots, degree = 2, intercept = TRUE) library(graphics) matplot(x, msMat, type = "l", ylab = "M-spline basis")## 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))