MsplineBasis: M-Spline Basis for Polynomial Splines

View source: R/MsplineBasis.R

MsplineBasisR Documentation

M-Spline Basis for Polynomial Splines

Description

Generate the M-spline basis matrix for a polynomial spline.

Usage

MsplineBasis(x, df = NULL, knots = NULL, degree = 3, intercept = FALSE,
             Boundary.knots = range(x), periodic = FALSE)

Arguments

x

the predictor variable. Missing values are not allowed.

df

degrees of freedom; if specified the number of knots is defined as df - degree - ifelse(intercept, 1, 0); the knots are placed at the quantiles of x

knots

the internal breakpoints that define the spline (typically the quantiles of x)

degree

degree of the piecewise polynomial—default is 3 for cubic splines

intercept

if TRUE, the basis includes an intercept column

Boundary.knots

boundary points for M-spline basis; defaults to min and max of x

periodic

if TRUE, the M-spline basis is constrained to be periodic

Details

Syntax is adapted from the bs function in the splines package (R Core Team, 2021).

Used for implementing various types of smoothness constraints in the cmls fucntion.

Value

A matrix of dimension c(length(x), df) where either df was supplied or df = length(knots) + degree + ifelse(intercept, 1, 0)

Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

References

R Core Team (2023). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/

Ramsay, J. O. (1988). Monotone regression splines in action. Statistical Science, 3, 425-441. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/ss/1177012761")}

See Also

IsplineBasis

Examples

x <- seq(0, 1, length.out = 101)
M <- MsplineBasis(x, df = 8, intercept = TRUE)
M <- scale(M, center = FALSE)
plot(x, M[,1], ylim = range(M), t = "l")
for(j in 2:8) lines(x, M[,j], col = j)

CMLS documentation built on April 3, 2023, 5:24 p.m.