random_group_component_names() returns the names of the grouping variables of a compiled random-effect term. random_group_prediction_keys() assigns each row of a data frame the key of its group, so that the rows of new data can be matched to the fitted groups of the term (or to groups that were not fitted) when random effects are predicted or marginalized.

random_group_component_names(term)

random_group_prediction_keys(term, data)

Arguments

term

a compiled random-effect term (a list), see the details.

data

a data frame with the grouping variables of term and one row per observation to be keyed.

Value

random_group_component_names() returns a character vector of the names of the grouping variables of term.

random_group_prediction_keys() returns a character vector with one key per row of data: the key of the fitted group for rows in a fitted group of term, and a distinct key for rows in a new group.

Details

A compiled random-effect term is an element of the random_effects of a formula design: the design returned by JAGS_formula() (JAGS_formula(...)$formula_design$random_effects[[i]]) or the design stored with a fit or with draws (JAGS_formula_design(fit, parameter)$random_effects[[i]]). Pass the element unchanged; its fields are not part of the public interface.

An interaction (g1:g2) or nested (g1/g2) grouping expression has one grouping variable per component, returned in the order of the fitted groups.

The keys of random_group_prediction_keys() are character strings whose format is not part of the interface. Rows with the same grouping values share a key; a row whose grouping values identify a fitted group of the term has the key of that group, and a row with values that are not a fitted group has a key of its own that differs from the keys of all fitted groups. A grouping value is matched to the fitted levels by its exact value; a value that matches no fitted level but equals the label (or the displayed value) of exactly one fitted level takes that level, and a label shared by several fitted levels stops with an error. A term without its fitted grouping ownership (a design stored by an earlier version) stops with an error of class BayesTools_refit_required. A grouping variable that is missing in data or contains missing values stops with an error.