Builds the formula design of a formula parameter exactly as
JAGS_fit() builds it from its formula_list,
formula_data_list, formula_prior_list, and the related
arguments (through JAGS_formula()), with its model data as
model_data, and attaches it to posterior or
prior draws that do not come from such a fit, for example the prior draws
of a model that was not fitted. JAGS_evaluate_formula() and
JAGS_predict_formula() evaluate the returned draws through this design as
they evaluate a fit: on data when their data is NULL,
and on new prediction data with the levels, contrasts, and
standardization of data.
JAGS_formula_draws(
draws,
formula,
parameter,
data,
prior_list,
formula_scale = NULL,
prior_random = NULL,
random_effects_compile = NULL,
model_data = NULL
)posterior or prior draws of the model coordinates: a numeric
matrix or data frame with one column per coordinate, named as the fitted
coordinates (e.g. mu_intercept, mu_x, mu_g[1]), or an
mcmc or mcmc.list object (chains are merged). Draws returned
by JAGS_formula_draws() keep their designs, so that the designs of
several formula parameters can be attached one after another.
formula specifying the right hand side of the assignment (the
left hand side is ignored), or a BayesTools_random_effects object returned
by random_effects_formula(). If the formula suppresses the intercept with
0 + or -1, it is converted to include an intercept with a
spike(0) prior.
The formula can also have a "log(intercept)" attribute set to TRUE
to generate syntax of the form log(intercept) + sum(beta_i * x_i), which
is useful for parameters that must be positive (e.g., standard deviation).
In that case, the intercept prior must have strictly positive support.
valid unindexed JAGS node name of the parameter to be created with the formula
data.frame the formula is fitted to: it determines the factor levels and the standardization of the design.
named list of prior distribution of parameters specified within
the formula. The name "intercept" is reserved for the intercept:
no other predictor or prior name may contain the substring "intercept".
When suppressing the intercept in the formula, an
"intercept" prior can be explicitly specified; otherwise,
prior("spike", list(0)) is
automatically added, or prior("spike", list(1)) when the formula uses
the "log(intercept)" attribute. The list can also include two special entries:
"__default_continuous"A prior to use for any continuous predictors (including the intercept) that are not explicitly specified in the prior list. This can also be a zero-argument function returning a prior object; in that case it is evaluated only if a missing continuous term needs the default.
"__default_factor"A prior to use for any factor predictors (including interactions involving factors) that are not explicitly specified in the prior list. This can also be a zero-argument function returning a prior object; in that case it is evaluated only if a missing factor term needs the default.
These default priors allow for more concise specification when many predictors
share the same prior distribution. For continuous formula terms,
prior_none() is canonicalized to a point prior at zero.
The prior of a formula term can carry a "multiply_by" attribute (a
number or the name of another parameter) that multiplies the term's
contribution to the linear predictor; the intercept prior cannot be scaled
and a "multiply_by" attribute on it is an error. For a mixture or
spike-and-slab prior, set the attribute on that prior itself; a component
carrying one is an error.
named list specifying whether to standardize continuous predictors.
If NULL (default), no standardization is applied. If a named list is provided,
continuous predictors with TRUE values will be standardized (mean-centered and
scaled by standard deviation). The intercept is never standardized. Scaled
predictors are centered in every fixed and random term, including terms
without a free intercept, so the model is specified on the standardized
scale; see Details.
optional prior_random() object defining random-effect
standard-deviation, covariance, monitoring, and prediction policies. Required
when formula contains random effects.
optional random_effects_compile() object
specifying which resolved random-effect blocks should be compiled as sampled
random effects and which should be compiled as structural marginalized
blocks.
optional named list of the JAGS model data of the fit, as
the data argument of JAGS_fit(). expression() terms of
formula may read these data besides data; the design keeps
the data they read, as the fitted design does. The data are also retained
for expression-point coefficient dependencies and scalar multiplier/SD
sources. Owned point-expression arrays retain their original dimensions
independently of prediction-row counts.
An mcmc object of the draws carrying the formula design of
parameter (see JAGS_formula_design()) and, when predictors are
standardized, its formula_scale, which JAGS_evaluate_formula() and
JAGS_predict_formula() accept as fit.