View source: R/decide_variable_type_univariate.R
decide_variable_type_univariate | R Documentation |
For each numeric predictor, this function fits a shallow (maxdepth = 2
) rpart
tree
directly on Y ~ x
and tests whether a dummy transformation improves model fit.
decide_variable_type_univariate(
X,
Y,
minsplit = 5,
criterion = c("AIC", "BIC"),
exclude_vars = NULL,
verbose = FALSE
)
X |
A data frame of numeric predictors (no response). |
Y |
A numeric response vector. |
minsplit |
Minimum number of observations in a node to consider splitting. Default = 5. |
criterion |
A character string: either |
exclude_vars |
A character vector of variable names to exclude from dummy transformations.
These variables will always be treated as linear. Default = |
verbose |
Logical; if |
Dummy forms come from a shallow (maxdepth = 2
) rpart
tree fit to the data. We extract up to two splits:
Single cutoff dummy (e.g., x >= c
)
Double cutoff dummy (e.g., c1 < x < c2
)
The function then picks the form (linear, single-split dummy, or double-split dummy)
that yields the lowest AIC/BIC. If a variable is listed in exclude_vars
, it will always be used
as a linear predictor (dummy transformation is never attempted).
A named list of decisions, where each element is a list with:
Either "dummy"
or "linear"
.
A numeric vector (length 1 or 2) if type = "dummy"
, or NULL
if linear.
The fitted rpart
model (for reference) or NULL
if excluded.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.