Skip to content
forked from wwiecek/baggr

R package for Bayesian meta-analysis models, using Stan

License

Notifications You must be signed in to change notification settings

jc-castillo/baggr

 
 

Repository files navigation

baggr

CRAN_Status_Badge Travis build status codecov

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 (v0.5, June 2020) is a stable version of a tool that’s in active development so we are counting on your feedback.

Installation

Before starting, baggr will not work if you don’t have RStan, which is responsible for Bayesian inference in baggr. In that case, please follow the installation instructions for RStan.

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; for this, you will need the devtools package.

# compilation of models should take 5-10 minutes
devtools::install_github("wwiecek/baggr", 
                         build_vignettes = TRUE,
                         build_opts = c("--no-resave-data", "--no-manual"))

Basic use case

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.

Current and future releases

Included in baggr v0.5 (June 2020):

  • Meta-analysis and hierarchical models for 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 effect modelling capabilities
  • Compatibility with rstan and bayesplot features
  • Automatic choice of priors or “plain-text” specification of priors
  • Automatic calculation of pooling metrics
  • Cross-validation (including leave-one-group-out)
  • Prior and posterior predictive distributions

In the coming months (summer 2020) we will be including more models and more features such as:

  • Modelling of quantiles and of variances
  • Better modelling of log-normal data
  • Automatic standardisation of variables
  • More model diagnostics

About

R package for Bayesian meta-analysis models, using Stan

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • R 92.2%
  • Stan 7.6%
  • C++ 0.2%