data(mtcars)
n <- nrow(mtcars)
# Formula method
cvLM(
mpg ~ .,
data = mtcars,
K.vals = n, # Leave-one-out CV
lambda = 10 # Shrinkage parameter of 10
)
# lm method
my.lm <- lm(mpg ~ ., data = mtcars)
cvLM(
my.lm,
data = mtcars,
K.vals = c(5L, 8L), # Perform both 5- and 8-fold CV
n.threads = 8L, # Allow up to 8 threads for computation
seed = 1234L
)
# glm method
my.glm <- glm(mpg ~ ., data = mtcars)
cvLM(
my.glm,
data = mtcars,
K.vals = n, generalized = TRUE # Use generalized CV
)
Run the code above in your browser using DataLab