Prior Definitions for
Define priors for specific parameters or classes of parameters
set_prior(prior, class = "b", coef = "", group = "")
- A character string defining a distribution in
- The parameter class. Defaults to
"b"(fixed effects). See 'Details' for other valid parameter classes.
- Name of the (fixed, category specific, or random effects) parameter
- Grouping factor for random effects parameters.
set_prior is used to define prior distributions for parameters
the name of the corresponding fixed effect.
Suppose, for instance, that
y is predicted by
y ~ x1+x2 in formula syntax).
x2 have regression parameters
The default prior for fixed and category specific effects is an
improper flat prior over the reals. Other common options are normal priors
or student-t priors. If we want to have a normal prior with mean 0 and
standard deviation 5 for
and a unit student-t prior with 10 degrees of freedom for
we can specify this via
set_prior("normal(0,5)", class = "b", coef = "x1") and
set_prior("student_t(10,0,1)", class = "b", coef = "x2").
To put the same prior on all fixed effects at once,
we may write as a shortcut
This also leads to faster sampling, because priors can be vectorized in this case.
Both ways of defining priors can be combined using for instance
set_prior("normal(0,2)", class = "b") and
set_prior("normal(0,10)", class = "b", coef = "Intercept")
at the same time. This will set a
normal(0,10) prior on
the Intercept and a
normal(0,2) prior on all other fixed effects.
The intercept can have a separate prior without breaking vectorization.
However, this is not the case for other fixed effects.
A special shrinkage prior to be applied on fixed effects is the horseshoe prior.
It is symmetric around zero with fat tails and an infinitely large spike
at zero. This makes it ideal for sparse models that have
many regression coefficients,although only a minority of them is non-zero.
For more details see Carvalho et al. (2009).
The horseshoe prior can be applied on all fixed effects at once
(excluding the intercept) by using
with the desired degrees of freedom of the student-t prior
of the local shrinkage parameters.
In their paper, Carvalho et al. (2009) use one degrees of freedom, but this
my lead to an increased number of divergent transition in
0.8 to values closer to
1 will often be necessary.
See the documentation of
brm for instructions
on how to increase
3. Autocorrelation parameters
The autocorrelation parameters currently implemented are named
ma (moving average),
arr (autoregression of the response).
The default prior for autocorrelation parameters is an
improper flat prior over the reals.
Other priors can be defined by
ar effects and similar for
4. Standard deviations of random effects
Each random effect of each grouping factor has a standard deviation named
sd_. Consider, for instance, the formula
y ~ x1+x2+(1+x1|g).
We see that the intercept as well as
x1 are random effects
nested in the grouping factor
The corresponding standard deviation parameters are named as
These parameters are restriced to be non-negative and, by default,
have a half cauchy prior with a scale parameter that depends on the
standard deviation of the response after applying the link function.
Minimally, the scale parameter is 5.
To define a prior distribution only for standard deviations
of a specific grouping factor,
To define a prior distribution only for a specific standard deviation
of a specific grouping factor, you may write
Recommendations on useful prior distributions for
standard deviations are given in Gelman (2006).
5. Correlations of random effects
If there is more than one random effect per grouping factor,
the correlations between those random
effects have to be estimated.
"lkj_corr_cholesky(eta)" or in short
eta > 0
is essentially the only prior for (choelsky factors) of correlation matrices.
eta = 1 (the default) all correlations matrices
are equally likely a priori. If
eta > 1, extreme correlations
become less likely, whereas
0 < eta < 1 results in
higher probabilities for extreme correlations.
Correlation matrix parameters in
brms models are named as
g is the grouping factor).
To set the same prior on every correlation matrix,
use for instance
set_prior("lkj(2)", class = "cor").
6. Parameters for specific families
Some families need additional parameters to be estimated.
need the parameter
to account for the residual standard deviation.
sigma has a half cauchy prior that scales
in the same way as the random effects standard deviations.
student needs the parameter
nu representing the degrees of freedom of students t distribution.
nu has prior
and a fixed lower bound of
negbinomial need a
shape parameter that has a
"cauchy(0,5)" prior by default.
acat, and only if
threshold = "equidistant",
delta is used to model the distance between
two adjacent thresholds.
delta has an improper flat prior over the reals.
Every family specific parameter has its own prior class, so that
set_prior(" it the right way to go.
Often, it may not be immediately clear,
which parameters are present in the model.
To get a full list of parameters and parameter classes for which
priors can be specified (depending on the model)
- An object of class
brmspriorto be used in the
Gelman A (2006). Prior distributions for variance parameters in hierarchical models. Bayesian analysis, 1(3), 515 -- 534. Carvalho, C. M., Polson, N. G., & Scott, J. G. (2009). Handling sparsity via the horseshoe. In International Conference on Artificial Intelligence and Statistics (pp. 73-80).
## check which parameters can have priors get_prior(rating ~ treat + period + carry + (1|subject), data = inhaler, family = sratio(), threshold = "equidistant") ## define some priors prior <- c(set_prior("normal(0,10)", class = "b"), set_prior("normal(1,2)", class = "b", coef = "treat"), set_prior("cauchy(0,2)", class = "sd", group = "subject", coef = "Intercept"), set_prior("uniform(-5,5)", class = "delta")) ## verify that the priors indeed found their way into Stan's model code make_stancode(rating ~ period + carry + (1|subject), data = inhaler, family = sratio(), partial = ~ treat, threshold = "equidistant", prior = prior) ## use horseshoe priors to model sparsity in fixed effects parameters make_stancode(count ~ log_Age_c + log_Base4_c * Trt_c, data = epilepsy, family = poisson(), prior = set_prior("horseshoe(3)"))