This is baggr, an R package for Bayesian meta-analysis using Stan. Baggr is intended to be user-friendly and transparent so that it’s easier to understand the models you are building and criticise them.
Baggr provides a suite of models that work with both summary data and
full data sets, to synthesise evidence collected from different groups,
contexts or time periods. The baggr()
command automatically detects
the data type and, by default, fits a partial pooling model (which you
may know as random effects
models)
with weakly informative priors by calling Stan
to carry out Bayesian inference. Modelling of variances or quantiles,
standardisation and transformation of data is also possible.
The current version is a stable version of a tool that’s in active development so we are counting on your feedback.
Before starting, please follow the installation instructions for RStan, which is responsible for Bayesian inference in baggr. If you don’t have Stan, it’s worth following the instructions step-by-step.
The package itself is available on CRAN:
install.packages("baggr")
You can also install the most up-to-date version of baggr
directly
from GitHub; this is what we recommend, but to do that you will need the
remotes
package:
#installation this way may take 5-15 minutes
remotes::install_github("wwiecek/baggr",
ref = "devel", #if problems try changing to ref = "master"
build_vignettes = TRUE, quiet = TRUE,
build_opts = c("--no-resave-data", "--no-manual"))
Most common issue in installing baggr is with updating other packages.
Try updating your packages (and ensure R is at least version 4) before
trying the remotes
command.
baggr
is designed to work well with both individual-level (“full”) and
aggregate/summary (“group”) data on treatment effect. In basic cases,
only the summary information on treatment effects (such as means and
their standard errors) is needed. Data are always specified in a single
input data frame and the same baggr()
function is used for different
models.
For the “standard” cases of modelling means, the appropriate model is detected from the shape of data.
library(baggr)
df_pooled <- data.frame("tau" = c(28,8,-3,7,-1,1,18,12),
"se" = c(15,10,16,11,9,11,10,18))
bg <- baggr(df_pooled, pooling = "partial")
You can specify the model type from several choices, the pooling type
("none"
, "partial"
or "full"
), and certain aspects of the priors,
as well as other options for data preparation, prediction and more. You
can access the underlying stanfit
object through bg$fit
.
Flexible plotting methods are included, together with an automatic
comparison of multiple models (e.g. comparing no, partial and full
pooling) through baggr_compare()
command. Various statistics can be
calculated: in particular, pooling()
for pooling metrics and loocv()
for leave-one-group-out cross-validation, allowing us to then compare
and select models via loo_compare()
. Forest plots and plots of
treatment effects are available.
Try vignette('baggr')
for an overview of these functions and an
example of meta-analysis workflow with baggr
. If working with binary
data, try vignette("baggr_binary")
. Compiled vignettes are available
on CRAN.
Included in baggr v0.7 (2023):
- Meta-analysis of continuous and binary outcomes
- Both full and aggregate data sets can be used
- Summaries and plots specific to meta-analysis, typical diagnostic plots
- Meta-regression / fixed effects modelling
- Compatibility with
rstan
andbayesplot
features - Automatic choice of priors or “plain-text” specification of priors
- Calculation of pooling/heterogeneity metrics
- Cross-validation (leave-one-group-out)
- Prior and posterior predictive distributions
Check [NEWS.md] for more information on recent changes to the package.