Skip to contents

brms's loo_model_weights() on draws from frm_sample(): the frmtmb::log_lik() matrix of each model and its relative efficiency, handed to loo::loo_model_weights(), which stacks the leave-one-out predictive densities (method = "stacking", the default) or weights the models by pseudo-BMA. posterior_average() takes its "stacking" and "pseudobma" weights from the same function.

Usage

# S3 method for class 'frmtmb_draws'
loo_model_weights(x, ..., model_names = NULL)

Arguments

x

A frmtmb_draws from frm_sample().

...

Further draws objects, without names unless the name is the label to use; then loo::loo_model_weights()'s own options (method, optim_method, optim_control, BB, BB_n, alpha, cores), and ndraws, draw_ids and resp (either spelling), which reach every model's frmtmb::log_lik(). newdata and the new-level arguments are refused unless they hold brms's default.

model_names

Labels for the models. The default deparses the arguments, as brms does.

Value

loo's weights object, named by model.

Examples

# \donttest{
if (requireNamespace("tmbstan", quietly = TRUE) &&
    requireNamespace("rstan", quietly = TRUE) &&
    requireNamespace("loo", quietly = TRUE) &&
    !frmtmb.sample:::tmbstan_build_broken()) {
  set.seed(9)
  dd <- data.frame(x = rnorm(60))
  dd$y <- rnorm(60, 1 + 0.5 * dd$x, 1)
  d1 <- frm_sample(bf(y ~ x), family = gaussian(), data = dd,
                   chains = 2, iter = 500, refresh = 0)
  d2 <- frm_sample(bf(y ~ 1), family = gaussian(), data = dd,
                   chains = 2, iter = 500, refresh = 0)
  loo_model_weights(d1, d2)
}
#> frm_sample(): default priors (brms 2.23 defaults; prior = "flat" puts brms's (flat) in every slot)
#>   Intercept          student_t(3, 0.8, 2.5)
#>   sigma              student_t(3, 0, 2.5)  [natural scale]
#>   b                  (flat), as brms leaves slopes
#> frm_sample(): default priors (brms 2.23 defaults; prior = "flat" puts brms's (flat) in every slot)
#>   Intercept          student_t(3, 0.8, 2.5)
#>   sigma              student_t(3, 0, 2.5)  [natural scale]
#>   b                  (flat), as brms leaves slopes
#> Method: stacking
#> ------
#>    weight
#> d1 1.000 
#> d2 0.000 
# }