View source: R/step_collinear.R
| step_collinear | R Documentation |
Adds a step to a recipe created by recipes::recipe()]+ to apply multicollinearity filtering via collinear().
This function requires the recipes package to be installed.
Unlike collinear(), this wrapper does not perform target encoding, and the default value for the argument quiet is TRUE.
step_collinear(
recipe,
...,
role = NA,
trained = FALSE,
options = list(),
selected = NULL,
skip = FALSE,
keep_original_cols = FALSE,
id = recipes::rand_id("collinear")
)
## S3 method for class 'step_collinear'
prep(x = NULL, training = NULL, info = NULL, ...)
## S3 method for class 'step_collinear'
bake(object = NULL, new_data = NULL, ...)
recipe |
(required, recipe) A recipe object to which this step will be added. |
... |
(optional) Additional arguments (currently ignored). |
role |
(optional, character) Not used by this step since no new variables are created. Default: NA |
trained |
(optional, logical) Indicates if the step has been trained. Default: FALSE |
options |
(optional, list) Named list of arguments passed to
Note: |
selected |
(character vector) Predictors retained after filtering. Populated during training and used during baking. Default: NULL |
skip |
(optional, logical) Trigger to skip this step when baking. Default: FALSE. |
keep_original_cols |
(optional, logical) Whether to keep original columns. Default: FALSE. |
id |
(optional, character) Unique identifier for this step. |
x |
(required, step_collinear object) The step to be trained. Default: NULL |
training |
(required, data.frame) The training dataset used to estimate quantities. |
info |
(optional, data.frame) Preprocessed information about variables in |
object |
(required, |
new_data |
(required, data.frame) New data to apply the step to. Default: NULL |
Updated recipe with new step.
Other multicollinearity_filtering:
collinear(),
collinear_select(),
cor_select(),
vif_select()
## Not run:
if(requireNamespace("recipes", quietly = TRUE) &&
requireNamespace("parsnip", quietly = TRUE) &&
requireNamespace("workflows", quietly = TRUE)
){
data(
vi_smol,
vi_predictors_numeric
)
# model formula
vi_formula <- collinear::model_formula(
df = vi_smol,
response = "vi_numeric",
predictors = vi_predictors_numeric
)
# recipe
vi_recipe <- recipes::recipe(
formula = vi_formula,
data = vi_smol
) |>
#multicollinearity filtering
collinear::step_collinear(
recipes::all_predictors(),
options = list(
max_cor = 0.7,
max_vif = 5,
f = collinear::f_numeric_glm
)
) |>
#normalization
recipes::step_normalize(
recipes::all_predictors()
)
# define linear regression model
vi_model <- parsnip::linear_reg() |>
parsnip::set_engine("lm")
# create and fit workflow
vi_workflow <- workflows::workflow() |>
workflows::add_recipe(vi_recipe) |>
workflows::add_model(vi_model) |>
workflows::fit(data = vi_smol)
vi_workflow
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.