Learn R Programming

trtswitch (version 0.1.4)

bscpp: B-Spline Basis for Polynomial Splines

Description

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

Usage

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

Value

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.

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.

Author

Kaifeng Lu, kaifenglu@gmail.com

Examples

Run this code

bscpp(women$height, df = 5)

Run the code above in your browser using DataLab