step_spline_b: step_spline_b

View source: R/api_recipes.R

step_spline_bR Documentation

step_spline_b

Description

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 than knots, then the function chooses df - degree - as.integer(intercept) internal knots at suitable quantiles of x ignoring missing values and those x outside of the boundary. For periodic splines, df - as.integer(intercept) internal knots will be chosen at suitable quantiles of x 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 specified degree - 1. If internal knots are specified via knots, the specified df 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 is FALSE.

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.

Value

an updated recipe

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")


jkennel/hydrorecipes documentation built on Dec. 24, 2024, 5:38 p.m.