step_spline_b
step_spline_b.Rd
generates basis splines.
Usage
step_spline_b(
.rec,
terms,
df = 0L,
internal_knots = NULL,
boundary_knots = NULL,
intercept = FALSE,
periodic = FALSE,
degree = 3L,
role = "predictor",
...
)
Arguments
- .rec
the R6 recipe object.
- terms
the unquoted names of the variables to use or a selector function. terms replaces the `...` of the recipes package but requires variables to be included within `c()`. For example to include variables x and y you would write `c(x,y)` in the hydrorecipes package.
- df
Degree of freedom that equals to the column number of the returned matrix. One can specify
df
rather thanknots
, then the function choosesdf - degree - as.integer(intercept)
internal knots at suitable quantiles ofx
ignoring missing values and thosex
outside of the boundary. For periodic splines,df - as.integer(intercept)
internal knots will be chosen at suitable quantiles ofx
relative to the beginning of the cyclic intervals they belong to (see Examples) and the number of internal knots must be greater or equal to the specifieddegree - 1
. If internal knots are specified viaknots
, the specifieddf
will be ignored.- internal_knots
equivalent to knots from `splines2::bSplines`
- boundary_knots
equivalent to Boundary.knots from `splines2::bSplines`
- intercept
If
TRUE
, the complete basis matrix will be returned. Otherwise, the first basis will be excluded from the output.- periodic
A logical value. If
TRUE
, the periodic splines will be returned. The default value isFALSE
.- degree
A nonnegative integer specifying the degree of the piecewise polynomial. The default value is
3
for cubic splines. Zero degree is allowed for piecewise constant basis functions.- role
character - the name of the role
- ...
Optional arguments that are not used.
Examples
formula <- as.formula(x~y+z)
rows <- 1e5
dat <- data.frame(x = rnorm(rows),
y = 1:rows,
z = cumsum(rnorm(rows)))
ik <- collapse::fquantile(dat$x, probs = seq(0, 1, 0.1))
bk <- ik[c(1, length(ik))]
ik <- ik[-c(1, length(ik))]
frec = recipe(formula = formula, data = dat) |>
step_spline_b(x, df = 11L, intercept = FALSE) |>
plate("tbl")