When selecting variables or model terms in
dplyr-like tools are used. The selector functions
can choose variables based on their name, current role, data
type, or any combination of these. The selectors are passed as
any other argument to the step. If the variables are explicitly
stated in the step function, this might be similar to:
The first four arguments indicate which variables should be
used in the PCA while the last argument is a specific argument
These arguments are not evaluated until the
function for the step is executed.
dplyr-like syntax allows for negative signs to
exclude variables (e.g.
-Murder) and the set of selectors will
processed in order.
A leading exclusion in these arguments (e.g.
has the effect of adding all variables to the list except the
Select helpers from the
tidyselect package can also be used:
would only select
Columns of the design matrix that may not exist when the step
is coded can also be selected. For example, when using
step_pca(), the number of columns created by feature extraction
may not be known when subsequent steps are defined. In this
matches("^PC") will select all of the columns
whose names start with "PC" once those columns are created.
There are sets of recipes-specific functions that can be used to select
variables based on their role or type:
has_type(). For convenience, there are also functions that are
more specific. The functions
based on type, with nominal variables including both character and factor;
all_outcomes() select based on role.
Any can be used in conjunction with the previous functions described for
selecting variables using their names:
1 2 3
This results in all the numeric predictors: carbon, hydrogen, oxygen, nitrogen, and sulfur.
If a role for a variable has not been defined, it will never be selected using role-specific selectors.
Selectors can be used in
step_interact() in similar ways but
must be embedded in a model formula (as opposed to a sequence
of selectors). For example, the interaction specification
~ starts_with("Species"):Sepal.Width. This can be
Species was converted to dummy variables
step_dummy(). The implementation of
step_interact() is special, and is more restricted than
the other step functions. Only the selector functions from
recipes and tidyselect are allowed. User defined selector functions
will not be recognized. Additionally, the tidyselect domain specific
language is not recognized here, meaning that
will not work.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.