Example 1: Bayesian (General) Linear Models

Now that you’ve read the Get started section, let’s dive in the subtleties of Bayesian modelling using R.

Loading the packages

Once you’ve installed the necessary packages, we can load rstanarm (to fit the models) and bayestestR (to compute useful indices).

library(rstanarm)
library(bayestestR)

A Linear Model

Fitting the model

model <- stan_glm(Sepal.Length ~ Petal.Length, data=iris)

Extracting the posterior

posteriors <- insight::get_parameters(model)
plot(density(posteriors$Petal.Length))