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
)

Arguments

draws

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

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.

parameter

valid unindexed JAGS node name of the parameter to be created with the formula

data

data.frame the formula is fitted to: it determines the factor levels and the standardization of the design.

prior_list

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.

formula_scale

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.

prior_random

optional prior_random() object defining random-effect standard-deviation, covariance, monitoring, and prediction policies. Required when formula contains random effects.

random_effects_compile

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.

model_data

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.

Value

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.