# Introduction and setup

This lesson picks up where Lesson 2 left off, continuing along with a practical introduction to fitting Bayesian multilevel models in R and Stan using the brms package (Bayesian Regression Models using Stan).

## What did we learn in Lessons 1 and 2?

So far, we have covered the basics of Bayesian inference and learned about the basic components of a Bayesian model (prior, likelihood, and posterior). Weâ€™ve used the R package brms to fit Bayesian linear mixed models using the Hamiltonian Monte Carlo method, with the Stan language doing the sampling behind the scenes. Weâ€™ve learned some tricks to deal with convergence issues when sampling. Weâ€™ve used the posterior distributions from our models to make inferences: weâ€™ve calculated credible intervals, plotted model parameters and predictions, compared models with information criteria, and done hypothesis testing with Bayesian-style p-values. That was all Lesson 1!

In Lesson 2, we explored prior distributions in more depth and learned how the inference you make can be sensitive to your choice of prior, especially if youâ€™re working with small data. Then we learned how to specify and fit Bayesian GLMs (for non-normal data) and GLMMs (for non-normal data with random effects). We now know what response distributions and link function we can use if we have binary response data or positive right-skewed data.

## What will we learn in Lesson 3?

Another piece of feedback I got when I taught the first Bayesian workshop is that people are interested in learning how to specify more complex model structures that go along with typical experimental designs in agricultural science. I think this lesson helps address that need. In ag science, we often have data collected over time and space. Usually, we can assume that the closer in time or space two data points are, the more they will be correlated with one another. In this lesson, we are going to learn how to account for that non-independence in time or space when we are trying to estimate an effect. We will learn:

• How to fit a linear mixed model with residuals that are correlated in time (repeated measures in time)
• How to fit a linear mixed model to a split plot design, and add a spatial additive component to the model

## Space and time

The basic insight that you need to have to understand why specialized model structures are needed to deal with data collected over time and space is this: the closer two things are in time or space, the more closely related they are. In a spatial context, this is known as the First Law of Geography.