Setting priors with brms

Suppose I would like to set a Gamma prior for “sigma” with shape = 20 and scale = 100. How do I do that? Below are some options. Also, could someone please point me to official documentation where I can read about how to code priors correctly?

``````library(brms)

#Option 1:

brmout <- brm(
formula = brmsformula(y ~ 0 + group, sigma ~ 0 + group),
prior   = c(
set_prior("gamma(20, 100)", class = "b", coef = "group", dpar = "sigma"),
set_prior("gamma(20, 100)", class = "b", coef = "group", dpar = "sigma")
)

#Option 2:

brmout <- brm(
formula = brmsformula(y ~ 0 + group, sigma ~ 0 + group),
prior   = c(
set_prior("gamma(20, 1/100)", class = "b", coef = "group", dpar = "sigma"),
set_prior("gamma(20, 1/100)", class = "b", coef = "group", dpar = "sigma")
)

#Option 3:

brmout <- brm(
formula = brmsformula(y ~ 0 + group, sigma ~ 0 + group),
prior   = c(
set_prior("gamma(log(20), log(100))", class = "b", coef = "group", dpar = "sigma"),
set_prior("gamma(log(20), log(100))", class = "b", coef = "group", dpar = "sigma")
)

#Option 4:

brmout <- brm(
formula = brmsformula(y ~ 0 + group, sigma ~ 0 + group),
prior   = c(
set_prior("gamma(log(20), log(1/100))", class = "b", coef = "group", dpar = "sigma"),
set_prior("gamma(log(20), log(1/100))", class = "b", coef = "group", dpar = "sigma")
)

``````

there’s the prior choice wiki, last updated 2020 - it has some recommendations for degrees of freedom in student’s t - link below

2 Likes

@gpsmith, as to your specific priors, keep in mind brms uses the shape-rate parameterization for the gamma distribution when you’re setting priors. So in your case, you’d set something like your option #2:

`set_prior("gamma(20, 1/100)", class = "b", coef = "group", dpar = "sigma")`

But I would only recommend this if you were using the identity link for sigma. Since you’re using the log link instead, I’d recommend you switch to a Gaussian or Student-t prior.

3 Likes