Supervised Factor Conversions into Linear Functions using Bayesian Likelihood Encodings
Source:R/lencode_mixed.R
step_lencode_mixed.Rd
step_lencode_mixed()
creates a specification of a recipe step that will
convert a nominal (i.e. factor) predictor into a single set of scores derived
from a generalized linear mixed model.
Arguments
- recipe
A recipe object. The step will be added to the sequence of operations for this recipe.
- ...
One or more selector functions to choose variables. For
step_lencode_mixed
, this indicates the variables to be encoded into a numeric format. Seerecipes::selections()
for more details. For thetidy
method, these are not currently used.- role
Not used by this step since no new variables are created.
- trained
A logical to indicate if the quantities for preprocessing have been estimated.
- outcome
A call to
vars
to specify which variable is used as the outcome in the generalized linear model. Only numeric and two-level factors are currently supported.- options
A list of options to pass to
lme4::lmer()
orlme4::glmer()
.- mapping
A list of tibble results that define the encoding. This is
NULL
until the step is trained byrecipes::prep()
.- skip
A logical. Should the step be skipped when the recipe is baked by
recipes::bake()
? While all operations are baked whenrecipes::prep()
is run, some operations may not be able to be conducted on new data (e.g. processing the outcome variable(s)). Care should be taken when usingskip = TRUE
as it may affect the computations for subsequent operations- id
A character string that is unique to this step to identify it.
Value
An updated version of recipe
with the new step added to the
sequence of existing steps (if any). For the tidy
method, a tibble with
columns terms
(the selectors or variables for encoding), level
(the
factor levels), and value
(the encodings).
Details
For each factor predictor, a generalized linear model is fit to the outcome and the coefficients are returned as the encoding. These coefficients are on the linear predictor scale so, for factor outcomes, they are in log-odds units. The coefficients are created using a no intercept model and, when two factor outcomes are used, the log-odds reflect the event of interest being the first level of the factor.
For novel levels, a slightly timmed average of the coefficients is returned.
A hierarchical generalized linear model is fit using lme4::lmer()
or
lme4::glmer()
, depending on the nature of the outcome, and no intercept via
where the ...
include the family
argument (automatically set by the step)
as well as any arguments given to the options
argument to the step.
Relevant options include control
and others.
Tidying
When you tidy()
this step, a tibble is retruned with
columns level
, value
, terms
, and id
:
- level
character, the factor levels
- value
numeric, the encoding
- terms
character, the selectors or variables selected
- id
character, id of this step
Case weights
This step performs an supervised operation that can utilize case weights.
To use them, see the documentation in recipes::case_weights and the examples on
tidymodels.org
.