R/projpred.R
get_refmodel.brmsfit.Rd
The get_refmodel.brmsfit
method can be used to create the reference
model structure which is needed by the projpred package for performing
a projection predictive variable selection. This method is called
automatically when performing variable selection via
varsel
or
cv_varsel
, so you will rarely need to call
it manually yourself.
get_refmodel.brmsfit(
object,
newdata = NULL,
resp = NULL,
cvfun = NULL,
dis = NULL,
latent = FALSE,
brms_seed = NULL,
...
)
An object of class brmsfit
.
An optional data.frame for which to evaluate predictions. If
NULL
(default), the original data of the model is used.
NA
values within factors are interpreted as if all dummy
variables of this factor are zero. This allows, for instance, to make
predictions of the grand mean when using sum coding.
Optional names of response variables. If specified, predictions are performed only for the specified response variables.
Optional cross-validation function
(see get_refmodel
for details).
If NULL
(the default), cvfun
is defined internally
based on kfold.brmsfit
.
Passed to argument dis
of
init_refmodel
, but leave this at
NULL
unless projpred complains about it.
See argument latent
of
extend_family
. Setting this to
TRUE
requires a projpred version >= 2.4.0.
A seed used to infer seeds for kfold.brmsfit
and for sampling group-level effects for new levels (in multilevel models).
If NULL
, then set.seed
is not called at all. If not
NULL
, then the pseudorandom number generator (PRNG) state is reset
(to the state before calling this function) upon exiting this function.
Further arguments passed to
init_refmodel
.
A refmodel
object to be used in conjunction with the
projpred package.
The extract_model_data
function used internally by
get_refmodel.brmsfit
ignores arguments wrhs
and orhs
(a warning is thrown if these are non-NULL
). For example, arguments
weightsnew
and offsetnew
of
proj_linpred
,
proj_predict
, and
predict.refmodel
are passed to
wrhs
and orhs
, respectively.
if (FALSE) {
# fit a simple model
fit <- brm(count ~ zAge + zBase * Trt,
data = epilepsy, family = poisson())
summary(fit)
# The following code requires the 'projpred' package to be installed:
library(projpred)
# perform variable selection without cross-validation
vs <- varsel(fit)
summary(vs)
plot(vs)
# perform variable selection with cross-validation
cv_vs <- cv_varsel(fit)
summary(cv_vs)
plot(cv_vs)
}