bayes4psy—User Friendly Bayesian Data Analysis for Psychology

R-CMD-check CRAN_Status_BadgeDownloads


Jure Demšar, Grega Repovš and Erik Štrumbelj

The package

This is an R package intended for Bayesian statistical analysis in the field of psychology. Psychology is one of the fields where the replication crisis is the most prominent. Scientist believe that one of the main reason for this might be non-transparent and inappropriate use of frequentist statistics. We believe that using fully transparent Bayesian methods provided in this package could greatly alleviate the replication crisis in psychology.

We also prepared several examples where we used the bayes4psy package to perform Bayesian data analysis for scientific publications on actual data gathered by psychological tests. These examples can be found on our GitHub repository. This repository also includes short test scenarios (these scenarios execute all developed functionalities on dummy data) intended for debugging the package.

This readme document provides only a brief overview of the package, a detailed description of all implemented functions is provided in package’s help pages.


Bayesian models in the bayes4psy package are written with the Stan language. Stan functions required for working with these models are accessed via the RStan package. There are currently five models in the package:

Model fitting

The fitted model objects returned by the bayes4psy package are called b_results objects. These objects contain three components, extract contains values of fitted parameters, fit is the original stanfit object and data is the input data used for fitting. To fit a model to the data one has to first prepare the input data and then call an appropriate fitting function:

If no priors are provided as parameters for fitting functions, then flat (improper) priors are put on all parameters. See provided examples and tests to see how one can specify their own priors.

Analyzing fits

To enable users without extensive programming knowledge to perform professional level Bayesian data analysis we developed a number of custom methods. Below is a short description of functions common to all models, for descriptions of functions specific to certain models consult the package’s help pages.


Development Version

You can install the development version from GitHub. To do so you first have to install the RStan package and C++ toolchain (instructions). Once RStan and the toolchain are installed, you can install bayes4psy by using the devtools package in R:

if (!require(devtools)) {


The research behind this software was partially funded by the Slovenian Research Agency (ARRS) through grants L1-7542 (Advancement of computationally intensive methods for efficient modern general-purpose statistical analysis and inference), P3-0338 (Physiological mechanisms of neurological disorders and diseases), J3-9264 (Decomposing cognition: working memory mechanism and representations), P5-0410 (Digitalization as driving force for sustainability of individuals, organizations, and society), and P5-0110 (Psychological and neuroscientific aspects of cognition).