Learn R Programming

trtswitch (version 0.1.4)

nscpp: Natural Cubic Spline Basis

Description

Computes the B-spline basis matrix for a natural cubic spline.

Usage

nscpp(
  x = NA_real_,
  df = NA_integer_,
  knots = NA_real_,
  intercept = 0L,
  boundary_knots = NA_real_
)

Value

A matrix with dimensions c(length(x), df), where df is either provided directly or computed as length(knots) + 1 + intercept when knots are supplied. The matrix contains attributes that correspond to the arguments passed to the nscpp function.

Arguments

x

A numeric vector representing the predictor variable. Missing values are allowed.

df

Degrees of freedom, specifying the number of columns in the basis matrix. If df is provided, the function selects df - 1 - 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 provided, the number of degrees of freedom will be determined by the length of knots.

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 natural boundary conditions are applied and the B-spline basis is anchored. If not supplied, the default is the range of non-missing values in x.

Author

Kaifeng Lu, kaifenglu@gmail.com

Examples

Run this code

nscpp(women$height, df = 5)

Run the code above in your browser using DataLab