Site icon R-bloggers

Describe and understand Bayesian models and posteriors using bayestestR

[This article was first published on R on easystats, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.33 47.61]
##           wt  rejected      0.00 % [-4.14 -1.01]
##          cyl undecided     36.84 % [-1.87  0.34]
##         gear undecided     40.75 % [-2.18  1.78]
##           am undecided     18.17 % [-1.18  4.58]
##           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!

To leave a comment for the author, please follow the link and comment on their blog: R on easystats.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.