brms's prior_draws(): the draws frm_sample() made from the
priors with sample_prior = "yes", under brms's names without the
prior_ prefix.
Usage
prior_draws(x, ...)
# S3 method for class 'frmtmb_draws'
prior_draws(x, variable = NULL, pars = NULL, ...)Arguments
- x
A
frmtmb_drawsfromfrm_sample().- ...
Unused.
- variable
Names of the variables whose prior draws to return, or
NULLfor every prior draw.- pars
brms's deprecated alias of
variable; it warns.
Value
A data frame with one column per prior (or per name in
variable) and one row per post-warmup draw.
Details
Each column is one prior statement of brms's Stan program for the
model. A prior on a whole class is one column (b, sd_g, sigma);
where a coefficient has a prior of its own, each coefficient of that
vector is a column (b_x, sd_g__Intercept). A flat prior has no
column, so with brms's defaults there is no b. A bounded parameter
is drawn from its prior truncated to the bounds (sigma and sd at
0, nu at 1). A correlation is one off-diagonal element of an
LKJ draw (cor_g, rescor), a mo() simplex or a mixture's weights
a Dirichlet draw (simo_mox1[1], ...). Intercept is drawn from the
prior of the intercept at the centered predictors, which is where
brms puts that prior.
With variable, each name gets the column whose name is the longest
match at its start, and the draws in random order, as brms does, so
that two names sharing a column are not paired draw by draw: b_x
and b_z both read b. A name nothing matches is left out. The
population-level intercept of a model with a centered intercept
(b_Intercept) has no prior draws: brms warns and leaves it out, and
so does this method.
Draws made with sample_prior = "no" (the default) or "only" have
no prior draws, and the result is an empty data frame. Under
"only" the draws themselves are draws from the prior.
The draws are made directly from each prior with R's random number
generators, as brms makes them in Stan's generated quantities, so they
are independent and do not depend on the likelihood. With seed
given to frm_sample() they are reproducible.
See also
hypothesis(), which divides the posterior density of a point hypothesis by its prior density read from these draws.
Examples
# \donttest{
if (requireNamespace("tmbstan", quietly = TRUE) &&
requireNamespace("rstan", quietly = TRUE) &&
!frmtmb.sample:::tmbstan_build_broken()) {
set.seed(9)
dd <- data.frame(x = rnorm(60), g = factor(rep(1:6, 10)))
dd$y <- rnorm(60, 1 + 0.5 * dd$x + rnorm(6, 0, 0.5)[dd$g], 1)
ds <- frm_sample(bf(y ~ x + (1 | g)), family = gaussian(), data = dd,
prior = set_prior("normal(0, 1)", class = "b"),
sample_prior = "yes", chains = 1, iter = 500,
seed = 1, refresh = 0)
head(prior_draws(ds))
# the prior draws of one coefficient are the class's
summary(prior_draws(ds, "b_x")$b_x)
# the Savage-Dickey evidence ratio of a point hypothesis reads them
hypothesis(ds, "x = 0")
}
#> frm_sample(): default priors (brms 2.23 defaults; prior = "flat" puts brms's (flat) in every slot)
#> Intercept student_t(3, 0.8, 2.5)
#> sigma student_t(3, 0, 2.5) [natural scale]
#> sd student_t(3, 0, 2.5) [natural sd scale]
#> b (flat), as brms leaves slopes
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> Hypothesis Tests for class b:
#> Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob Star
#> 1 (x) = 0 0.51 0.12 0.27 0.74 0 0 *
#> ---
#> 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
#> '*': For one-sided hypotheses, the posterior probability exceeds 95%;
#> for two-sided hypotheses, the value tested against lies outside the 95%-CI.
#> Posterior probabilities of point hypotheses assume equal prior probabilities.
# }