--- title: "Example 1: Bayesian (General) Linear Models" output: github_document: toc: true fig_width: 10.08 fig_height: 6 rmarkdown::html_vignette: toc: true fig_width: 10.08 fig_height: 6 tags: [r, bayesian, posterior, test] vignette: > \usepackage[utf8]{inputenc} %\VignetteIndexEntry{Example 1: Bayesian (General) Linear Models} %\VignetteEngine{knitr::rmarkdown} editor_options: chunk_output_type: console bibliography: bibliography.bib --- Now that you've read the [**Get started**](https://easystats.github.io/bayestestR/articles/bayestestR.html) section, let's dive in the subtleties of Bayesian modelling using R. ## Loading the packages Once you've [installed](https://easystats.github.io/bayestestR/articles/bayestestR.html) the necessary packages, we can load `rstanarm` (to fit the models) and `bayestestR` (to compute useful indices). ```{r message=FALSE, warning=FALSE} library(rstanarm) library(bayestestR) ``` ## A Linear Model ### Fitting the model ```{r message=FALSE, warning=FALSE, eval=FALSE} model <- stan_glm(Sepal.Length ~ Petal.Length, data=iris) ``` ```{r echo=FALSE, message=FALSE, warning=FALSE, comment=NA, results='hide'} library(rstanarm) set.seed(333) model <- stan_glm(Sepal.Length ~ Petal.Length, data=iris) ``` ### Extracting the posterior ```{r message=FALSE, warning=FALSE, eval=FALSE} posteriors <- insight::get_parameters(model) ``` ```{r message=FALSE, warning=FALSE, eval=FALSE} plot(density(posteriors$Petal.Length)) ```