Build a B-spline basis for a numeric vector using a Cox-de Boor style recursion. By default, the function constructs a cubic spline basis (P = 3) and chooses the number of basis functions from the number of unique values in x.
Arguments
- x
A numeric vector of predictor values.
- P
A non-negative integer giving the spline degree.
P = 3corresponds to a cubic B-spline basis.- K
An integer giving the number of basis functions to return. The default increases slowly with the number of unique values in
x.- limits
A numeric vector of length 2 giving the lower and upper boundary limits for the spline basis. Missing values are replaced by
min(x)andmax(x).- knots
Either a numeric vector of knot locations, or one of
"eq"or"quantile". If"eq", knots are placed uniformly betweenlimits[1]andlimits[2]. If"quantile", knots are placed at equally spaced empirical quantiles ofx.
Details
Boundary limits are taken from x unless supplied explicitly. Knot locations may be given directly as a numeric vector, or generated either at equally spaced locations ("eq") or at empirical quantiles ("quantile").
The returned basis has length(x) rows and k columns.
When knots is generated internally, the function first creates K - P + 1 knot locations and then augments them with repeated boundary knots so the recursion can be evaluated.