Ranks N models by LOO and/or WAIC, returning a sorted hbm_table.
Analogous to loo_compare.
Usage
model_compare_all(..., criterion = c("loo", "waic", "both"))Value
A hbm_table (a sorted data.frame) with columns
Model, ELPD_LOO, LOO_SE, LOO_rank (and
analogous *_WAIC* columns when requested).
Examples
# \donttest{
library(hbsaems)
library(brms)
data("data_fhnorm")
FAST <- list(chains = 4, iter = 2000, warmup = 1000, cores = 1,
seed = 1, refresh = 0)
m1 <- do.call(hbm, c(list(formula = brms::bf(y ~ x1),
data = data_fhnorm), FAST))
#> Warning: Model fitted without any area-level random effects.
#> This is unusual for Small Area Estimation: the standard Fay-Herriot model assumes u_i ~ N(0, sigma_u^2) per area, so estimates from a purely fixed-effects model will not borrow strength across areas.
#> Consider one of:
#> re = ~ (1 | area_id) # IID area RE
#> spatial_var = 'area_id', spatial_model = 'car', M = W # CAR spatial RE
#> spatial_var = 'area_id', spatial_model = 'sar', M = W # SAR spatial RE
#> If a fixed-effects-only baseline is intentional, you can suppress this warning with `suppressWarnings()`.
#> Compiling Stan program...
#> Start sampling
m2 <- do.call(hbm, c(list(formula = brms::bf(y ~ x1 + x2),
data = data_fhnorm), FAST))
#> Warning: Model fitted without any area-level random effects.
#> This is unusual for Small Area Estimation: the standard Fay-Herriot model assumes u_i ~ N(0, sigma_u^2) per area, so estimates from a purely fixed-effects model will not borrow strength across areas.
#> Consider one of:
#> re = ~ (1 | area_id) # IID area RE
#> spatial_var = 'area_id', spatial_model = 'car', M = W # CAR spatial RE
#> spatial_var = 'area_id', spatial_model = 'sar', M = W # SAR spatial RE
#> If a fixed-effects-only baseline is intentional, you can suppress this warning with `suppressWarnings()`.
#> Compiling Stan program...
#> Start sampling
model_compare_all(simple = m1, medium = m2)
#> Model Comparison Table [hbm_table]
#> =====================================
#>
#> Model ELPD_LOO LOO_SE n_high_k LOO_rank
#> medium -180.9472 7.709664 0 1
#> simple -183.1146 7.341436 0 2
#>
#> Best model: medium
# }