Generates the I-spline (integral of M-spline) basis matrix for a polynomial spline or the corresponding derivatives of given order.
Usage
iSpline(
x,
df = NULL,
knots = NULL,
degree = 3L,
intercept = TRUE,
Boundary.knots = NULL,
derivs = 0L,
...
)
Arguments
- 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 the returned matrix. One can specify
df
rather thanknots
, then the function choosesdf - degree - as.integer(intercept)
internal knots at suitable quantiles ofx
ignoring missing values and thosex
outside of the boundary. If internal knots are specified viaknots
, the specifieddf
will be ignored.- knots
The internal breakpoints that define the splines. 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.- degree
The degree of I-spline defined to be the degree of the associated M-spline instead of actual polynomial degree. For example, I-spline basis of degree 2 is defined as the integral of associated M-spline basis of degree 2.
- intercept
If
TRUE
by default, all of the spline basis functions are returned. Notice that when using I-Spline for monotonic regression,intercept = TRUE
should be set even when an intercept term is considered additional to the spline basis functions.- Boundary.knots
Boundary points at which to anchor the splines. By default, they are the range of
x
excludingNA
. If bothknots
andBoundary.knots
are supplied, the basis parameters do not depend onx
. Data can extend beyondBoundary.knots
.- derivs
A nonnegative integer specifying the order of derivatives of I-splines.
- ...
Optional arguments that are not used.
Value
A numeric matrix of 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
mainly for other functions in this package.
Details
It is an implementation of the closed-form I-spline basis based on the recursion formula given by Ramsay (1988).
References
Ramsay, J. O. (1988). Monotone regression splines in action. Statistical Science, 3(4), 425--441.
Examples
library(splines2)
## Example given in the reference paper by Ramsay (1988)
x <- seq.int(0, 1, by = 0.01)
knots <- c(0.3, 0.5, 0.6)
isMat <- iSpline(x, knots = knots, degree = 2)
op <- par(mar = c(2.5, 2.5, 0.2, 0.1), mgp = c(1.5, 0.5, 0))
matplot(x, isMat, type = "l", ylab = "I-spline basis")
abline(v = knots, lty = 2, col = "gray")
## reset to previous plotting settings
par(op)
## the derivative of I-splines is M-spline
msMat1 <- iSpline(x, knots = knots, degree = 2, derivs = 1)
msMat2 <- mSpline(x, knots = knots, degree = 2, intercept = TRUE)
stopifnot(all.equal(msMat1, msMat2))