This project contains a very simple simulation to explore two implementations of Beyesian mixed modeling. The simulation creates data with a linear relationship between one covariate and a response variable with an intercept that varies by site nested within species.
The Stan code is a literal implementation of the simulation code with just a few small changes:
The stan_lmer() model is the the direct analog of the simulation and the Stan code, except that it uses a decov() prior for all of the random effect.
results.txt contains the results from analysis of 100 simulated datasets. You’ll notice that the bias, root mean squared error, and coverage (symmetric 80% credible intervals) are very similar for the intercept (beta_0), the regression coefficient (beta_1), and the residual standard deviatiion (sigma). The random effect standard deviations (sigma_species and sigma_species_site) are fairly different from one another. In both cases, the Stan code has a smaller bias and root mean squared error and it has better coverage properties.