For this, you need lag
to also be outside (lag | group)
as in
fit_ppool <- stan_glmer(value ~ lag + (lag | group), data = example,
algorithm = “meanfield”, prior = normal(0,1))
That is just part of the lme4 syntax. What you had originally forces the population-level slope to be zero, which is usually not what anyone wants. That is why
This is done via the prior_covariance
argument even though there is only a standard deviation in your case. By setting that equal to decov(shape = 2, scale = 1.5)
you get a gamma prior with that shape and scale on the standard deviation in the coefficient on lag
across levels of group
.
Also, meanfield ADVI tends not to work well with stan_[g]lmer
.