splitwise {SplitWise} | R Documentation |
SplitWise Regression
Description
Transforms each numeric variable into either a single-split dummy or keeps it linear,
then runs stats::step()
for stepwise selection. The user can choose a
simpler univariate transformation or an iterative approach.
Usage
splitwise(
formula,
data,
transformation_mode = c("iterative", "univariate"),
direction = c("backward", "forward", "both"),
minsplit = 5,
criterion = c("AIC", "BIC"),
exclude_vars = NULL,
verbose = FALSE,
trace = 1,
steps = 1000,
k = 2,
...
)
## S3 method for class 'splitwise_lm'
print(x, ...)
## S3 method for class 'splitwise_lm'
summary(object, ...)
Arguments
formula |
A formula specifying the response and (initial) predictors, e.g. |
data |
A data frame containing the variables used in |
transformation_mode |
Either |
direction |
Stepwise direction: |
minsplit |
Minimum number of observations in a node to consider splitting. Default = 5. |
criterion |
Either |
exclude_vars |
A character vector naming variables that should be forced to remain linear
(i.e., no dummy splits allowed). Default = |
verbose |
Logical; if |
trace |
If positive, |
steps |
Maximum number of steps for |
k |
Penalty multiple for the number of degrees of freedom (used by |
... |
Additional arguments passed to |
x |
A |
object |
A |
Value
An S3 object of class c("splitwise_lm", "lm")
, storing:
splitwise_info |
List containing transformation decisions, final data, and call. |
Functions
-
print(splitwise_lm)
: Prints a summary of the splitwise_lm object. -
summary(splitwise_lm)
: Provides a detailed summary, including how dummies were created.
Examples
# Load the mtcars dataset
data(mtcars)
# Univariate transformations (AIC-based, backward stepwise)
model_uni <- splitwise(
mpg ~ .,
data = mtcars,
transformation_mode = "univariate",
direction = "backward",
trace = 0
)
summary(model_uni)
# Iterative approach (BIC-based, forward stepwise)
# Note: typically set k = log(nrow(mtcars)) for BIC in step().
model_iter <- splitwise(
mpg ~ .,
data = mtcars,
transformation_mode = "iterative",
direction = "forward",
criterion = "BIC",
k = log(nrow(mtcars)),
trace = 0
)
summary(model_iter)