sl_vglmer {vglmer} | R Documentation |
SuperLearner with (Variational) Hierarchical Models
Description
These functions integrate vglmer
(or glmer
) into
SuperLearner
. Most of the arguments are standard for
SuperLearner
functions.
Usage
SL.vglmer(
Y,
X,
newX,
formula,
family,
id,
obsWeights,
control = vglmer_control()
)
## S3 method for class 'SL.vglmer'
predict(object, newdata, allow_missing_levels = TRUE, ...)
SL.glmer(Y, X, newX, formula, family, id, obsWeights, control = NULL)
## S3 method for class 'SL.glmer'
predict(object, newdata, allow.new.levels = TRUE, ...)
add_formula_SL(learner, env = parent.frame())
Arguments
Y |
From |
X |
From |
newX |
From |
formula |
The formula used for estimation. |
family |
From |
id |
From |
obsWeights |
From |
control |
Control object for estimating |
object |
Used in |
newdata |
Dataset to use for predictions. |
allow_missing_levels |
Default ( |
... |
Not used; included to maintain compatibility with existing methods. |
allow.new.levels |
From |
learner |
Character name of model from |
env |
Environment to assign model. See "Details" for how this is used. |
Details
This documentation describes two types of function.
Estimating Hierarchical Models in SuperLearner: Two methods for
estimating hierarchical models are provided one for variational methods
(SL.vglmer
) and one for non-variational methods (SL.glmer
).
The accompanying prediction functions are also provided.
Formula with SuperLearner: The vglmer
package provides a way
to estimate models that require or use a formula with SuperLearner
.
This allows for a design to be passed that contains variables that are
not used in estimation. This can be used as follows (see
"Examples"). One calls the function add_formula_SL
around the quoted
name of a SuperLearner
model, e.g. add_formula_SL(learner =
"SL.knn")
. This creates a new model and predict function with the suffix
"_f"
. This requires a formula to be provided for estimation.
With this in hand, "SL.knn_f"
can be passed to SuperLearner
with the
accompanying formula argument and thus one can compare models with
different formula or design on the same ensemble. The env
argument
may need to be manually specified to ensure the created functions can be
called by SuperLearner
.
Value
The functions here return different types of output. SL.vglmer
and SL.glmer
return fitted models with the in-sample predictions as
standard for SuperLearner
. The predict
methods return vectors
of predicted values. add_formula_SL
creates two objects in the
environment (one for estimation model_f
and one for prediction
predict.model_f
) used for SuperLearner
.
Examples
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)}
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')
)
}