Skip to contents

`StepPca` Does PCA for a set of columns. This currently is an in house function. Use at your own risk!

Usage

step_pca(
  .rec,
  terms,
  na_rm = TRUE,
  n_comp = 3,
  center = TRUE,
  scale = TRUE,
  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.

na_rm

logical - should NA values be removed from calculations

n_comp

number of components to retain

center

center values before PCA

scale

scale values before PCA

role

character - the name of the role

...

additional arguments

Value

an updated recipe

Examples

set.seed(1)

formula <- as.formula(x~a+b+d+e+f+g)
rows <- 1000

dat <- data.frame(x = rnorm(rows),
                  a = rnorm(rows),
                  b = rnorm(rows),
                  d = rnorm(rows),
                  e = rnorm(rows),
                  f = rnorm(rows),
                  g = rnorm(rows))

rec  = recipe(formula = formula, data = dat) |>
  step_pca(c(x,a,b,d,e,f,g)) |>
  plate()