Estimating means and standard deviations
Before completing this assignment, please read the brms
walkthrough.
We fitted a gaussian model to some simple generated data. However, in the model we assumed that both groups had the same standard deviations. This assumption is not really necessary, however, as we can easily fit a model in which we allow both mean and standard deviation to vary between groups.
brms allows us easily fit both the main parameter (in this case the mean), as well as further distributional parameters. We simply need to wrap the formula in the bf()
function. Therefore, instead of the formula score ~ group
we can use this bf(score ~ group, sigma ~ group)
.
score ~ group
Can be replaced with:
bf(score ~ group, sigma ~ group)
Perform the steps described in the walkthrough, but this time for the model that allows both \(\mu\) and \(\sigma\) to vary. Does this model perform well? Are you able to recover the true parameter values?
NOTE: The standard deviation must be positive; therefore we are predicting log(sigma)
with our linear predictor. To recover the parameter on the original scale, you need to use the inverse function, which is the exponential function exp()
.
Try it out; if you get stuck, you can always ask questions on Zulip.
prior class coef group resp dpar nlpar
(flat) b
(flat) b groupB
student_t(3, 16.9, 2.5) Intercept
(flat) b sigma
(flat) b groupB sigma
student_t(3, 0, 2.5) Intercept sigma
bound source
default
(vectorized)
default
(vectorized)
(vectorized)
default
pp_check(m3)
pp_check(m3, type = "dens_overlay_grouped", group = "group")
If you see mistakes or want to suggest changes, please create an issue on the source repository.
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/awellis/learnmultilevelmodels, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Ellis (2021, May 24). Learn multilevel models: Assignment 1. Retrieved from https://awellis.github.io/learnmultilevelmodels/asssignment-1.html
BibTeX citation
@misc{ellis2021assignment, author = {Ellis, Andrew}, title = {Learn multilevel models: Assignment 1}, url = {https://awellis.github.io/learnmultilevelmodels/asssignment-1.html}, year = {2021} }