Stops with the declared typed refusal when the metadata of posterior draws mark a measure of a column as unavailable. The refusals are declared in the measure_unavailable field of the draws (posterior_metadata()), for example for the prior density of a quantity whose prior law cannot be certified. Calling it before the prior_density, atoms, or support metadata are read separates a refused measure from a measure that was never declared.

posterior_measure_check(x, measure, column = NULL)

Arguments

x

posterior draws with metadata, such as the results of as_mixed_posteriors(), mix_posteriors(), or marginal_posterior().

measure

the measure that is about to be read: "prior_density", "atoms", or "support".

column

NULL, or a character vector of the columns of x to check. NULL checks the column names of matrix draws, otherwise the column of the single declared quantity or the parameter attribute.

Value

posterior_measure_check() returns invisible(TRUE) when posterior_metadata(x, "measure_unavailable") has no entry for measure in column, and otherwise raises the refusal described in the details.

Details

Draws without a measure_unavailable declaration, and declarations of other measures or other columns, pass. When several entries match, the first one in the declaration table is raised. Stale or invalid draw metadata are refused by the metadata reader.

The refusal is an error condition with a NULL call, the message, and the fields target (the column), reason (the declared cause when the entry has one, otherwise the reason text), detail (the reason text of the entry), and diagnostics (the compact model probability diagnostics of the entry, or NULL). Its classes depend on the measure and end with "error" and "condition":

  • "prior_density": BayesTools_formula_prior_density_unavailable, BayesTools_formula_measure_unavailable (only when reason is an enumerated measure cause of the measure_unavailable metadata), and BayesTools_formula_transform_unavailable.

  • "atoms": BayesTools_formula_atoms_unavailable and, under the same condition, BayesTools_formula_measure_unavailable.

  • "support": BayesTools_formula_support_unavailable and, under the same condition, BayesTools_formula_measure_unavailable.

Callers should match these classes and the field reason rather than the message.

Examples

draws <- c(0.1, 0.2, 0.3)
attr(draws, "parameter") <- "theta"
posterior_metadata(draws, "measure_unavailable") <- data.frame(
  column  = "theta",
  measure = "atoms",
  reason  = "the atoms are not declared"
)

posterior_measure_check(draws, "support")
tryCatch(
  posterior_measure_check(draws, "atoms"),
  error = function(e) class(e)
)
#> [1] "BayesTools_formula_atoms_unavailable"
#> [2] "error"                               
#> [3] "condition"