bru_eval: Evaluate or sample from a posterior result given a model and...

bru_evalR Documentation

Evaluate or sample from a posterior result given a model and locations

Description

Evaluate

Usage

bru_eval(
  model,
  state,
  data = NULL,
  data_extra = NULL,
  input_comp = NULL,
  comp_mappers = NULL,
  predictor = NULL,
  format = NULL,
  used = NULL,
  ...
)

Arguments

model

A bru model

state

list of state lists, as generated by bru_state()

data

A list, data.frame, af, or Spatial*DataFrame, with coordinates and covariates needed to evaluate the predictor components.

data_extra

Additional data for the predictor evaluation

input_comp

Precomputed inputs list for the components

comp_mappers

Precomputed bm_list of full (as_bm_list(as_bru_comp_list(model))) , simplified, or linearised mappers for the components

predictor

A formula or a bru_pred_expr expression to be evaluated given the posterior or for each sample thereof. The default (NULL) returns a data.frame containing the sampled effects. In case of a formula the right hand side is used for evaluation.

format

character; determines the storage format of predictor output. Available options:

  • "auto" If the first evaluated result is a vector or single-column matrix, the "matrix" format is used, otherwise "list".

  • "matrix" A matrix where each column contains the evaluated predictor expression for a state.

  • "list" A list where each element contains the evaluated predictor expression for a state.

used

A bru_used() object, or NULL (default)

...

Additional arguments, unused.

Value

A matrix or list (see format) of evaluated predictor expressions.

Examples

if (bru_safe_inla()) {
  model <- bru_model(
    as_bru_comp_list(~ 1 + x + field(idx,
      model = "iid",
      mapper = bm_index(5L)
    )),
    bru_obs(
      y ~ Intercept + x + field,
      family = "poisson",
      data = data.frame(
        y = rpois(5, 10), x = rnorm(5),
        idx = c(1, 2, 3, 4, 5)
      )
    )
  )
  bru_eval(
    model,
    state = list(bru_state(model, property = "zeros")),
    data = data.frame(x = rnorm(4), idx = 4:1)
  )
  bru_eval(
    model,
    state = list(list(
      Intercept = 1, x = 2, field = c(0, 0, 0, 0, 0),
      Precision_for_field = 1
    )),
    data = data.frame(x = rnorm(4), idx = 4:1)
  )
  bru_eval(
    model,
    state = list(list(
      Intercept = 1, x = 2, field = c(0, 0, 0, 0, 0),
      Precision_for_field = 1
    )),
    data = data.frame(x = rnorm(4), idx = 4:1),
    predictor = new_bru_pred_expr(
      ~ list(a = Intercept + x + field, b = field_eval(c(5:7, 5:7)))
    )
  )
}


inlabru documentation built on July 28, 2026, 9:07 a.m.