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_
)
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.
A numeric vector representing the predictor variable. Missing values are allowed.
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.
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
.
A logical value indicating whether to include an
intercept in the basis. The default is FALSE
.
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
.
Kaifeng Lu, kaifenglu@gmail.com