brms's validate_prior(): resolve a prior specification against the
model it is meant for, refuse it if any part of it addresses nothing
the model has, and return the whole default_prior() table with the
prior filled in. Fitting runs the same check, so a prior this
function accepts is one frm() accepts, and a prior it refuses is
refused here with the message the fit would give, before any fitting
work.
Arguments
- prior
A
frmtmb_priorlistfromset_prior(), abrmsprior, orNULLfor none.- formula
A
bf()formula (with family) or a plain formula.- data
A data frame of model data (ignored when
objectis a fit).- family
Family, when
objectdoes not carry one.- data2
Structural objects, as in
frm()(ignored whenobjectis a fit, which carries its own).- route
Which route's defaults the
priorcolumn reports."fit"(the default) reports the defaultsfrm()applies, which are flat in every slot; it consults no registry, so its answer does not depend on which packages are attached."sample"reports the defaultsfrmtmb.sample::frm_sample()applies, and refuses when no package has registered any. The returned object records the route andprint()names it on its first line.
Value
A frmtmb_prior_rows table, as default_prior() returns.
Details
A row the prior sets reads source = "user". A row that takes its
density from a class row above it, the coefficients under a class
"b" prior or the blocks under a class "sd" prior, reads
source = "(vectorized)" and repeats that density, as brms prints
it. Every other row keeps its default.
Two specifications for the same slot are refused, as frm() and
brms refuse them. Where specifications for different slots reach one
parameter, the table shows the more specific one, which is the one
frm() applies; see set_prior().
The table can be passed back as prior =: frm() reads a
frmtmb_prior_rows table the way as.brmsprior() does, applying the
rows with a density or a bound and skipping the flat and
vectorized ones.
Examples
dd <- data.frame(y = rnorm(60), x = rnorm(60), z = rnorm(60),
g = factor(rep(1:6, 10)))
validate_prior(prior(normal(0, 10), class = b) +
prior(cauchy(0, 2), class = sd),
y ~ x + z + (1 | g), data = dd)
#> route = "fit": the prior defaults frm() applies
#> prior class coef group resp dpar nlpar lb ub source
#> 1 (flat) Intercept NA NA default
#> 2 normal(0, 10) b NA NA user
#> 3 normal(0, 10) b x NA NA (vectorized)
#> 4 normal(0, 10) b z NA NA (vectorized)
#> 5 cauchy(0, 2) sd NA NA user
#> 6 cauchy(0, 2) sd g NA NA (vectorized)
#> 7 cauchy(0, 2) sd Intercept g NA NA (vectorized)
#> 8 (flat) sigma NA NA default
# a prior on a coefficient the model does not have is refused
try(validate_prior(prior(normal(0, 1), coef = w), y ~ x, data = dd))
#> Error : Prior target not found (class=b, coef=w)