brm_multiple {brms}  R Documentation 
Run the same brms model on multiple datasets
Description
Run the same brms model on multiple datasets and then combine the results into one fitted model object. This is useful in particular for multiple missing value imputation, where the same model is fitted on multiple imputed data sets. Models can be run in parallel using the future package.
Usage
brm_multiple(
formula,
data,
family = gaussian(),
prior = NULL,
data2 = NULL,
autocor = NULL,
cov_ranef = NULL,
sample_prior = c("no", "yes", "only"),
sparse = NULL,
knots = NULL,
stanvars = NULL,
stan_funs = NULL,
silent = 1,
recompile = FALSE,
combine = TRUE,
fit = NA,
algorithm = getOption("brms.algorithm", "sampling"),
seed = NA,
file = NULL,
file_compress = TRUE,
file_refit = getOption("brms.file_refit", "never"),
...
)
Arguments
formula 
An object of class 
data 
A list of data.frames each of which will be used to fit a
separate model. Alternatively, a 
family 
A description of the response distribution and link function to
be used in the model. This can be a family function, a call to a family
function or a character string naming the family. Every family function has
a 
prior 
One or more 
data2 
A list of named lists each of which will be used to fit a
separate model. Each of the named lists contains objects representing data
which cannot be passed via argument 
autocor 
(Deprecated) An optional 
cov_ranef 
(Deprecated) A list of matrices that are proportional to the
(within) covariance structure of the grouplevel effects. The names of the
matrices should correspond to columns in 
sample_prior 
Indicate if draws from priors should be drawn
additionally to the posterior draws. Options are 
sparse 
(Deprecated) Logical; indicates whether the populationlevel
design matrices should be treated as sparse (defaults to 
knots 
Optional list containing user specified knot values to be used
for basis construction of smoothing terms. See

stanvars 
An optional 
stan_funs 
(Deprecated) An optional character string containing
selfdefined Stan functions, which will be included in the functions
block of the generated Stan code. It is now recommended to use the

silent 
Verbosity level between 
recompile 
Logical, indicating whether the Stan model should be
recompiled for every imputed data set. Defaults to 
combine 
Logical; Indicates if the fitted models should be combined
into a single fitted model object via 
fit 
An instance of S3 class 
algorithm 
Character string naming the estimation approach to use.
Options are 
seed 
The seed for random number generation to make results
reproducible. If 
file 
Either 
file_compress 
Logical or a character string, specifying one of the
compression algorithms supported by 
file_refit 
Modifies when the fit stored via the 
... 
Further arguments passed to 
Details
The combined model may issue false positive convergence warnings, as
the MCMC chains corresponding to different datasets may not necessarily
overlap, even if each of the original models did converge. To find out
whether each of the original models converged, investigate
fit$rhats
, where fit
denotes the output of
brm_multiple
.
Value
If combine = TRUE
a brmsfit_multiple
object, which
inherits from class brmsfit
and behaves essentially the same. If
combine = FALSE
a list of brmsfit
objects.
Author(s)
PaulChristian Buerkner paul.buerkner@gmail.com
Examples
## Not run:
library(mice)
imp < mice(nhanes2)
# fit the model using mice and lm
fit_imp1 < with(lm(bmi ~ age + hyp + chl), data = imp)
summary(pool(fit_imp1))
# fit the model using brms
fit_imp2 < brm_multiple(bmi ~ age + hyp + chl, data = imp, chains = 1)
summary(fit_imp2)
plot(fit_imp2, pars = "^b_")
# investigate convergence of the original models
fit_imp2$rhats
# use the future package for parallelization
library(future)
plan(multisession, workers = 4)
fit_imp3 < brm_multiple(bmi~age+hyp+chl, data = imp, chains = 1)
summary(fit_imp3)
## End(Not run)