Learn R Programming

splines2 (version 0.2.1)

cSpline: C-Spline Basis for Polynomial Splines

Description

This function generates the convex regression spline (called C-spline) basis matrix by integrating I-spline basis for a polynomial spline.

Usage

cSpline(x, df = NULL, knots = NULL, degree = 3, intercept = FALSE, Boundary.knots = range(x), scale = TRUE, ...)

Arguments

x
The predictor variable. Missing values are allowed and will be returned as they were.
df
Degrees of freedom. One can specify df rather than knots, then the function chooses "df - degree" (minus one if there is an intercept) knots at suitable quantiles of x (which will ignore missing values). The default, NULL, corresponds to no inner knots, i.e., "degree - intercept".
knots
The internal breakpoints that define the spline. 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. See also Boundary.knots.
degree
Non-negative integer degree of the piecewise polynomial. The default value is 3 for cubic splines.
intercept
If TRUE, an intercept is included in the basis; Default is FALSE.
Boundary.knots
Boundary points at which to anchor the C-spline basis. By default, they are the range of the non-NA data. If both knots and Boundary.knots are supplied, the basis parameters do not depend on x. Data can extend beyond Boundary.knots.
scale
Logical value (TRUE by default) indicating whether scaling on C-spline basis is required. If TRUE, C-spline basis is scaled to have unit height at right boundary knot; the corresponding I-spline and M-spline basis matrices shipped in attributes are also scaled to the same extent.
...
Optional arguments for future usage.

Value

A matrix of dimension length(x) by df = degree + length(knots) (plus on if intercept is included). Attributes that correspond to the arguments specified are returned for usage for predict.cSpline. The corresponding M-spline and I-spline basis matrices are also returned in attribute named msMat and isMat respectively.

Details

It is an implementation of the close form C-spline basis derived from the recursion formula of I-spline and M-spline. Internally, it calls iSpline and generates a basis matrix for representing the family of piecewise polynomials and their corresponding integrals with the specified interior knots and degree, evaluated at the values of x.

References

Meyer, M. C. (2008). Inference using shape-restricted regression splines. The Annals of Applied Statistics, 1013--1033. Chicago

See Also

predict.cSpline for evaluation at given (new) values; iSpline for I-spline basis; mSpline for M-spline basis; bSpline for B-spline basis; ibs for integral of B-spline basis.

Examples

Run this code
library(graphics)
x <- seq(0, 1, by = .01)
knots <- c(0.3, 0.5, 0.6)
cMat <- cSpline(x, knots = knots, degree = 2, intercept = TRUE)
matplot(x, cMat, type = "l", ylab = "C-spline basis")
abline(v = knots, lty = 2, col = "gray")
matplot(x, attr(cMat, "isMat"), type = "l", ylab = "scaled I-spline basis")
matplot(x, attr(cMat, "msMat"), type = "l", ylab = "scaled M-spline basis")

Run the code above in your browser using DataLab