Evaluate or sample from a posterior result given a model and locations
Source:R/model.R
bru_eval.RdEvaluate
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, orSpatial*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 adata.framecontaining 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.
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)))
)
)
}
#> [[1]]
#> [[1]]$a
#> [1] -0.7806468 2.5059217 1.8904319 1.8422124
#>
#> [[1]]$b
#> [,1]
#> [1,] 0.0000000
#> [2,] 1.1495922
#> [3,] -0.8963202
#> [4,] 0.0000000
#> [5,] 1.1495922
#> [6,] -0.8963202
#>
#>