step_spline_n: step_spline_n

View source: R/api_recipes.R

step_spline_nR Documentation

step_spline_n

Description

generates basis splines.

Usage

step_spline_n(
  .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 returned matrix. One can specify df rather than knots, then the function chooses df - 1 - as.integer(intercept) internal knots at suitable quantiles of x ignoring missing values and those x outside of the boundary. Thus, df must be greater than or equal to 2. 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.

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_n(x, df = 11L, intercept = FALSE)  |>
 plate("tbl")


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