bscpp function

B-Spline Basis for Polynomial Splines

B-Spline Basis for Polynomial Splines

Computes the B-spline basis matrix for a given polynomial spline.

bscpp( x = NA_real_, df = NA_integer_, knots = NA_real_, degree = 3L, intercept = 0L, boundary_knots = NA_real_, warn_outside = 1L )

Arguments

  • x: A numeric vector representing the predictor variable.
  • df: Degrees of freedom, specifying the number of columns in the basis matrix. If df is provided, the function automatically selects df - degree - intercept internal knots based on appropriate quantiles of x, ignoring any missing values.
  • knots: A numeric vector specifying the internal breakpoints that define the spline. If not provided, df must be specified.
  • degree: An integer specifying the degree of the piecewise polynomial. The default value is 3, which corresponds to cubic splines.
  • intercept: A logical value indicating whether to include an intercept in the basis. The default is FALSE.
  • boundary_knots: A numeric vector of length 2 specifying the boundary points where the B-spline basis should be anchored. If not supplied, the default is the range of non-missing values in x.
  • warn_outside: A logical value indicating whether a warning should be issued if any values of x fall outside the specified boundary knots.

Returns

A matrix with dimensions c(length(x), df). If df is provided, the matrix will have df columns. Alternatively, if knots are supplied, the number of columns will be length(knots) + degree + intercept. The matrix contains attributes that correspond to the arguments passed to the bscpp function.

Examples

bscpp(women$height, df = 5)

Author(s)

Kaifeng Lu, kaifenglu@gmail.com

  • Maintainer: Kaifeng Lu
  • License: GPL (>= 2)
  • Last published: 2025-03-20

Useful links