expand_spline: Expand feature matrix using basis splines

Description Usage Arguments Details Value References See Also Examples

View source: R/expand_spline.R

Description

Performs a basis expansion for many features at once, returning output that is compatible for use with the grpreg() function. Returns an expanded matrix along with a vector that describes its grouping.

Usage

1
expand_spline(x, df = 3, degree = 3, type = c("ns", "bs"))

Arguments

x

Features to be expanded (numeric matrix).

df

Degrees of freedom (numeric; default = 3).

degree

Degree of the piecewise polynomial (integer; default = 3 (cubic splines)).

type

Type of spline, either B-spline ("bs") or natural cubic spline ("ns"; default).

Details

expand_spline() uses the function splines::bs() or splines::ns() to generate a basis matrix for each column of x. These matrices represent the spline basis for piecewise polynomials with specified degree evaluated separately for each original column of x. These matrices are then column-bound to form a single grouped matrix of derived features. A vector that describes the grouping present in the resulting matrix is also generated. The resulting object can be passed to grpreg().

This methodology was originally proposed by Ravikumar et al. (2009), who named it SPAM (SParse Additive Modeling).

Value

An object of class expandedMatrix consisting of:

References

See Also

plot_spline() to visualize the resulting nonlinear fits

Examples

1
2
3
4
Data <- gen_nonlinear_data(n=1000)
X <- expand_spline(Data$X)
fit <- grpreg(X, Data$y)
plot_spline(fit, "V02", lambda = 0.03)

grpreg documentation built on July 27, 2021, 1:08 a.m.