# Linear model with VIF-based pruning
data(mtcars)
pruned <- modelPrune(mpg ~ ., data = mtcars, engine = "lm", limit = 5)
names(pruned)
# Force certain predictors to remain
pruned <- modelPrune(mpg ~ ., data = mtcars, force_in = "drat", limit = 20)
# GLM example (requires family argument)
pruned <- modelPrune(am ~ ., data = mtcars, engine = "glm",
family = binomial(), limit = 5)
if (FALSE) {
# Custom engine example (INLA)
inla_engine <- list(
name = "inla",
fit = function(formula, data, ...) {
inla::inla(formula = formula, data = data,
family = list(...)$family %||% "gaussian",
control.compute = list(config = TRUE))
},
diagnostics = function(model, fixed_effects) {
scores <- model$summary.fixed[, "sd"]
names(scores) <- rownames(model$summary.fixed)
scores[fixed_effects]
}
)
pruned <- modelPrune(y ~ x1 + x2 + x3, data = df,
engine = inla_engine, limit = 0.5)
}
Run the code above in your browser using DataLab