Fitting more than two levels in a multilevel model using rstanarm

It might be a simple question but I cannot seem to see examples anywhere on how to fit more than two levels for a multilevel (or hierarchical) model using rstanarm. I am learning how to do Bayesian analyses. and I have data I would like to run a Bayesian analysis on and my data has four levels. I saw examples that could fit two levels like this below:

TwoLevelModel <- stan_lmer(y ~ x + (1 + x | variable), data = dat)

If I want to fit four levels, how would I write a model using rstanarm? My four levels are: Quadrat nested into Transect nested into Site nested into Cape. Thank you!

It is the same as with lme4. Table 2 of

implies that it should involve | Quadrat / Transect / Site / Cape

1 Like