set.seed(456)
if (requireNamespace('SuperLearner', quietly = TRUE)){
require(SuperLearner)
sim_data <- data.frame(
x = rnorm(100),
g = sample(letters, 100, replace = TRUE)
)
sim_data$y <- rbinom(nrow(sim_data),
1, plogis(runif(26)[match(sim_data$g, letters)]))
sim_data$g <- factor(sim_data$g)
sl_vglmer <- function(...){SL.vglmer(..., formula = y ~ x + (1 | g))}
SL.glm <- SuperLearner::SL.glm
add_formula_SL('SL.glm')
sl_glm_form <- function(...){SL.glm_f(..., formula = ~ x)}
# \donttest{
SuperLearner::SuperLearner(
Y = sim_data$y, family = 'binomial',
X = sim_data[, c('x', 'g')],
cvControl = list(V = 2),
SL.library = c('sl_vglmer', 'sl_glm_form')
)
# }
}
Run the code above in your browser using DataLab