Generates the convex regression spline (called C-spline) basis matrix by integrating I-spline basis for a polynomial spline or the corresponding derivatives.
cSpline( x, df = NULL, knots = NULL, degree = 3L, intercept = TRUE, Boundary.knots = NULL, derivs = 0L, scale = TRUE, ... )
The predictor variable. Missing values are allowed and will be returned as they are.
Degree of freedom that equals to the column number of returned
matrix. One can specify
The internal breakpoints that define the spline. The default
The degree of C-spline defined to be the degree of the associated M-spline instead of actual polynomial degree. For example, C-spline basis of degree 2 is defined as the scaled double integral of associated M-spline basis of degree 2.
Boundary points at which to anchor the spline basis.
By default, they are the range of the non-
A non-negative integer specifying the order of derivatives of
C-splines. The default value is
Logical value (
Optional arguments that are not used.
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.
It is an implementation of the close form C-spline basis derived from the recursion formula of I-splines and M-splines.
Meyer, M. C. (2008). Inference using shape-restricted regression splines. The Annals of Applied Statistics, 1013--1033. Chicago
library(splines2) x <- seq.int(0, 1, 0.01) knots <- c(0.3, 0.5, 0.6) ### when 'scale = TRUE' (by default) csMat <- cSpline(x, knots = knots, degree = 2) par(mar = c(2.5, 2.5, 0.2, 0.1), mgp = c(1.5, 0.5, 0)) matplot(x, csMat, type = "l", ylab = "C-spline basis")abline(v = knots, lty = 2, col = "gray")isMat <- deriv(csMat) msMat <- deriv(csMat, derivs = 2) matplot(x, isMat, type = "l", ylab = "scaled I-spline basis")matplot(x, msMat, type = "l", ylab = "scaled M-spline basis")### when 'scale = FALSE' csMat <- cSpline(x, knots = knots, degree = 2, scale = FALSE) ## the corresponding I-splines and M-splines (with same arguments) isMat <- iSpline(x, knots = knots, degree = 2) msMat <- mSpline(x, knots = knots, degree = 2, intercept = TRUE) ## or using deriv methods (more efficient) isMat1 <- deriv(csMat) msMat1 <- deriv(csMat, derivs = 2) ## equivalent stopifnot(all.equal(isMat, isMat1, check.attributes = FALSE)) stopifnot(all.equal(msMat, msMat1, check.attributes = FALSE))