Describe and understand Bayesian models and posteriors using bayestestR

April 14, 2019
By

[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.18 46.99]
##           wt  rejected      0.00 % [-4.22 -1.03]
##          cyl undecided     35.83 % [-1.86  0.35]
##         gear undecided     43.86 % [-2.12  1.61]
##           am undecided     19.07 % [-1.23  4.32]
##           hp  accepted    100.00 % [-0.05  0.01]

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.



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)