if (requireNamespace("glmnet", quietly = TRUE))
{
form <- formula(mpg ~ cyl*wt*hp)
mf <- model.frame(form, data = mtcars)
mm <- model.matrix(mf, mf)
gtest <- glmnet::cv.glmnet(x = mm, y = mtcars$mpg, family = "gaussian")
imp <- importance(gtest, mtcars, form, nperm = 50)
plot(imp)
}
Run the code above in your browser using DataLab