Jure Demšar, Grega Repovš and Erik Štrumbelj
This is an R package intended for Bayesian statistical analysis inthe field of psychology. Psychology is one of the fields wherethe replicationcrisis is the most prominent. Scientist believe that one of the mainreason for this might be non-transparent and inappropriate use offrequentist statistics. We believe that using fully transparent Bayesianmethods provided in this package could greatly alleviate the replicationcrisis in psychology.
We also prepared several examples where we used thebayes4psy package to perform Bayesian data analysis forscientific publications on actual data gathered by psychological tests.These examples can be found on ourGitHubrepository. 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, adetailed description of all implemented functions is provided inpackage’s help pages.
Bayesian models in thebayes4psy package are writtenwith theStan language. Stan functionsrequired for working with these models are accessed via theRStan package. There are currently five models in thepackage:
The fitted model objects returned by thebayes4psypackage are calledb_results objects. These objects containthree components,extract contains values of fitted parameters,fit is the originalstanfit object anddatais the input data used for fitting. To fit a model to the data one hasto first prepare the input data and then call an appropriate fittingfunction:
If no priors are provided as parameters for fitting functions, thenflat (improper) priors are put on all parameters. See provided examplesand tests to see how one can specify their own priors.
To enable users without extensive programming knowledge to performprofessional level Bayesian data analysis we developed a number ofcustom methods. Below is a short description of functions common to allmodels, for descriptions of functions specific to certain models consultthe package’s help pages.
summary prints a summary of thefit.print,show prints a more detailed summary of thefit (same as RStan’sprint function).plot_fit visualize the quality of thefitted model against the input data.plot_trace construct a trace plot forrelevant parameters of the fitted model.get_parameters extracts the parametersof the fitted model.get_subject_parameters get parametersfor each subject (useful only for hierarchical models).plot_means visualize means for asingle or multiple fitted models.compare_means compare means betweentwo or more fitted models.plot_means_difference visualize thedifference of means between two or more fitted models.plot_distributions visualizedistributions underlying fitted models, can be used to visualize one ormore fitted models.compare_distributions draw and comparesamples from distributions underlying fitted models, can be used tocompare two or more fitted models.plot_distributions_differencevisualize the difference in distributions underlying fitted models, canbe used to compare two or more fitted models.You can install the development version from GitHub. To do so youfirst have to install theRStan package and C++toolchain (instructions).OnceRStan and the toolchain are installed, you caninstallbayes4psy by using thedevtools package in R:
if (!require(devtools)) {install.packages("devtools")library(devtools)}install_github("bstatcomp/bayes4psy")The research behind this software was partially funded by theSlovenian Research Agency (ARRS) through grants L1-7542 (Advancement ofcomputationally intensive methods for efficient modern general-purposestatistical analysis and inference), P3-0338 (Physiological mechanismsof neurological disorders and diseases), J3-9264 (Decomposing cognition:working memory mechanism and representations), P5-0410 (Digitalizationas driving force for sustainability of individuals, organizations, andsociety), and P5-0110 (Psychological and neuroscientific aspects ofcognition).