Describe and understand Bayesian models and posteriors using bayestestR

The Bayesian framework is quickly gaining popularity among scientists, leading to the growing popularity of packages to fit Bayesian models, such as rstanarm or brms. However, extracting summary indices from these models to report them in your manuscript can be quite challenging, especially for new users.

To address this, please let us introduce bayestestR!

bayestestR

We have recently decided to collaborate around the new easystats project, a set of packages designed to make your life easier (currently very WIP). As we are also Bayesian enthusiasts, we decided to focus on the development of a package devoted to Bayesian post-processing.

The goal of bayestestR is to provide lightweight tools to help processing and understanding Bayesian models and posterior distributions. It includes several functions used to report and characterise them, such as Highest Density Interval (hdi), the highest Maximum A Posteriori (MAP) or functions to find a suitable ROPE range, compute the ROPE percentage or do an Equivalence Test. It also includes more exploratory indices, such as the Probability of Direction (pd), a numeric equivalent of the frequentist p value.

bayestestR can be installed as follows:

install.packages("bayestestR")  # Install the package
library(bayestestR)  # Load it

Example

Let’s check whether the effects of my Bayesian regression can be considered as non-negligible. This can be done via the equivalence test.

# Load the rstanarm package
library(rstanarm)

# Fit a Bayesian model
model <- stan_glm(mpg ~ wt + cyl + gear + am + hp, data = mtcars)
# Do the test
equivalence_test(model)
## # Test for Practical Equivalence
## 
##   ROPE: [-0.60 0.60]
## 
## Parameter   |        H0 | inside ROPE |       89% HDI
## -----------------------------------------------------
## (Intercept) |  Rejected |      0.00 % | [27.11 47.28]
## wt          |  Rejected |      0.00 % | [-4.21 -1.05]
## cyl         | Undecided |     37.29 % | [-1.92  0.29]
## gear        | Undecided |     41.56 % | [-2.30  1.74]
## am          | Undecided |     20.13 % | [-1.29  4.73]
## hp          |  Accepted |    100.00 % | [-0.05  0.00]

Results can also be plotted, to get a better impression of the posterior distributions and the ROPE-coverage.

# Do the test and plot results
plot(equivalence_test(model))

More details about bayestestR’s features are comming soon, stay tuned ;)

Get Involved

There is definitely room for improvement, and some new exciting features are already planned (BayesFactor objects support, better visualisation methods, etc.). Feel free to let us know how we could further improve this package!

To conclude, note that easystats is a new project in active development. Thus, do not hesitate to contact us if you want to get involved :)

  • Check out our other blog posts here!