The easiest way to run Bayesian analyses in R is through the brms library. This library allows for the fitting of generalized linear and nonlinear multilevel models, using syntax similar to that of the lme4 library. The brms library uses Stan, which requires a C++ compiler. Running R Studio on Beocat through OpenOnDemand gives access to a C++ compiler, allows for multiple user-specified cores, and allows for time-consuming analyses to be run separately from your personal computer.
install.packages(“brms”)install.packages(“bayesplot”) , and ggplot 2 can be installed through install.packages(“ggplot2”) , or through the tidyverse package install.packages(“tidyverse”).dep=T to the end of your install command. Example: install.packages("brms",dep=T)For more information on brms, visit https://cran.r-project.org/web/packages/brms/readme/README.html.
For bayesplot information, visit https://mc-stan.org/bayesplot/.
In the setup for an R Studio OpenOnDemand Session, you can specify how many cores you would like to use. Similarly, you can designate a number of cores for the brms function to take advantage of in the syntax of your model.
For example, if you want to use 4 cores in your model, specify cores=4, in your model syntax:
library(brms)
Model1<-brm(DV ~ IV, data = mydata, prior=c(set_prior("normal(0,2)", class= "b")), chains = 4, cores=4)
Bayesian analyses through brms will run 4 chains by default, so by default it can take advantage of up to 4 cores in parallel. If you would like to run more chains parallelized across multiple cores, you can request the number of cores up to the number of chains you would like.
If you have been running models on your home computer, and would like to check how many cores you have, you can use:
library(parallel)
detectCores()
This is also useful for checking the number of cores available in your R OpenOnDemand session.
Note: there are methods for further parallelizing your chains. If you have a model that is taking multiple days to run, consider within chain parallelization. The specifics of this setup may depend on your model. If you need assistance making your model run faster, email karipayne@ksu.edu.
library(brms)
model1 <- brm(DV ~ IV, data=mydata)
summary(model1)
The summary() command will give you information about your MCMC (Markov Chain Monte Carlo) sampling (how many chains, iterations, warmups), your group level effects, and your main effects (called Population-Level Effects in the output).
plot(model1)
The plot() command will give you your distribution, and a visualization of your MCMC chains.

conditional_effects(model1)
The conditional_effects() command gives you figures of the individual effects of your IVs on your DV.
