prior() is set_prior() with the distribution given UNQUOTED, as
brms's prior() takes it: prior(normal(5000, 1000), nlpar = "ult")
is set_prior("normal(5000, 1000)", nlpar = "ult"). Every argument
is deparsed rather than evaluated, so class = b and class = "b"
mean the same thing, and a variable holding a distribution is
deparsed to its NAME rather than its value: use prior_string() to
build a prior from strings computed at run time.
Arguments
- prior
Distribution string, e.g.
"normal(0, 5)", or aprior_normal()/prior_t()/prior_lkj()object, or""for bounds only.- ...
Any of
set_prior()'s remaining arguments:class,coef,group,resp,dpar,nlpar,lb,ub.
Details
prior_() takes one-sided formulas, calls, names or constants
(prior_(~normal(0, 10), class = ~b)) and prior_string() takes
plain strings; both exist so that priors can be built
programmatically, and both are brms's.
A frmtmb prior and a brms prior are different objects, and with brms
attached after frmtmb its prior() masks this one. Nothing breaks:
frm() and frmtmb.sample::frm_sample() accept a brmsprior object
and translate its rows, so c(prior(...), prior(...)) copied out of a
brms script
works whichever prior() was in scope.
Examples
# the brms nonlinear vignette's spelling
prior(normal(5000, 1000), nlpar = "ult")
#> b_ult ~ normal(5000, 1000)
# combine with c() or `+`, as with set_prior()
c(prior(normal(1, 2), nlpar = "omega"),
prior(normal(45, 10), nlpar = "theta"))
#> prior class coef group resp dpar nlpar lb ub source
#> normal(1, 2) b omega <NA> <NA> user
#> normal(45, 10) b theta <NA> <NA> user
# the programmatic spellings
prior_(~normal(0, 10), class = ~b)
#> b ~ normal(0, 10)
prior_string(paste0("normal(0, ", 2 * 5, ")"), class = "b")
#> b ~ normal(0, 10)