View source: R/recipe_steps_robust.R
| step_cellpca | R Documentation |
step_cellpca() creates a specification of a recipe step that converts
the selected variables into robust principal component scores with
cellpca(), which weights the outlying cells and observations and
handles missing values.
step_cellpca(
recipe,
...,
role = "predictor",
trained = FALSE,
num_comp = 2,
options = list(),
prefix = "CPC",
distances = FALSE,
keep_original_cols = FALSE,
res = NULL,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("cellpca")
)
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
One or more selector functions to choose the predictors (for
example, the spectral channels). See |
role |
The role of the new score columns. Default is |
trained |
A logical indicating whether the step has been trained. |
num_comp |
The number of principal components. Default is 2. |
options |
A list of further arguments passed to |
prefix |
The prefix of the new column names. Default is |
distances |
A logical: add the score and orthogonal distances as
columns. Default is |
keep_original_cols |
A logical: keep the selected columns. Default is
|
res |
The fitted robust PCA model, stored once the step has been trained. |
columns |
The names of the selected columns, stored once the step has been trained. |
skip |
A logical. Should the step be skipped when the recipe is baked
by |
id |
A character string that is unique to this step. |
As step_robpca(). Missing values are allowed in the selected columns,
both when the recipe is prepped and when it is baked. New observations
are projected by the robust regression of their observed cells on the
loadings, so that their outlying cells do not distort their scores.
An updated version of recipe with the new step added to the
sequence of existing steps.
cellpca(), step_macropca(), step_robpca()
data(forageLIBS)
# potassium and the K I resonance lines
wl <- suppressWarnings(as.numeric(names(forageLIBS)))
dat <- forageLIBS[c(which(names(forageLIBS) == "K"), which(wl > 760 & wl < 780))]
set.seed(1)
rec <- recipes::recipe(K ~ ., data = dat[1:300, ]) |>
step_cellpca(recipes::all_predictors(), num_comp = 2, distances = TRUE,
options = list(od_cutoff = "chisq"))
recipes::bake(recipes::prep(rec), new_data = dat[301:368, ])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.