nscpp function

Natural Cubic Spline Basis

Natural Cubic Spline Basis

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

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

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.

Returns

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.

Examples

nscpp(women$height, df = 5)

Author(s)

Kaifeng Lu, kaifenglu@gmail.com

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

Useful links