From fb4acf846202cf4f1fd4a36f3455161d0ae17be6 Mon Sep 17 00:00:00 2001 From: Florence Bockting Date: Mon, 20 Apr 2026 14:58:11 +0300 Subject: [PATCH 1/4] fix: support new loo_compare output --- tests/testthat/test-loo_flocker.R | 12 ++++++++++-- vignettes/flocker_tutorial.Rmd | 27 +++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-loo_flocker.R b/tests/testthat/test-loo_flocker.R index d095e76..d846024 100644 --- a/tests/testthat/test-loo_flocker.R +++ b/tests/testthat/test-loo_flocker.R @@ -43,8 +43,16 @@ test_that("loo_compare_flocker works correctly", { # check model naming suppressWarnings(test_compare <- loo_compare_flocker(list(example_flocker_model_single2, example_flocker_model_single2), model_names = c("m1", "m2"), thin = 2)) - expect_identical(row.names(test_compare), c("m1", "m2")) + if ("model" %in% colnames(test_compare)) { + expect_identical(test_compare$model, c("m1", "m2")) + } else { + expect_identical(row.names(test_compare), c("m1", "m2")) + } # check test output identical - expect_true(all(apply(test_compare, 2, diff) == 0)) + if ("model" %in% colnames(test_compare)) { + expect_true(all(apply(test_compare[,c(2,3)], 2, diff) == 0)) + } else { + expect_true(all(apply(test_compare, 2, diff) == 0)) + } }) diff --git a/vignettes/flocker_tutorial.Rmd b/vignettes/flocker_tutorial.Rmd index 85b5967..2cb0c18 100644 --- a/vignettes/flocker_tutorial.Rmd +++ b/vignettes/flocker_tutorial.Rmd @@ -471,11 +471,18 @@ model. loo_compare_flocker( list(rep_constant, rep_varying) ) -#> Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. -#> Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. -#> elpd_diff se_diff -#> model2 0.0 0.0 -#> model1 -121.0 16.1 +#> Warning messages: +#> 1: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. + +#> 2: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. + +#> model elpd_diff se_diff p_worse diag_diff diag_elpd +#> model2 0.0 0.0 NA 2 k_psis > 0.7 +#> model1 -169.5 17.2 1.00 1 k_psis > 0.7 + +#> Diagnostic flags present. +#> See ?`loo-glossary` (sections `diag_diff` and `diag_elpd`) +#> or https://mc-stan.org/loo/reference/loo-glossary.html. ``` Likewise, we can compare the four flavors of multi-season model that we fit @@ -489,11 +496,11 @@ performs best: loo_compare_flocker( list(multi_colex, multi_colex_eq, multi_auto, multi_auto_eq) ) -#> elpd_diff se_diff -#> model1 0.0 0.0 -#> model2 -16.5 6.2 -#> model3 -41.7 9.5 -#> model4 -57.5 10.8 +#> model elpd_diff se_diff p_worse diag_diff diag_elpd +#> model1 0.0 0.0 NA +#> model3 -8.0 4.1 0.98 +#> model2 -27.1 7.2 1.00 +#> model4 -32.9 7.8 1.00 ``` Flocker also provides the function `loo_flocker()` to return a table of From eeab1c4f60c4ae5276d3facbaa47e2b9d0a4393d Mon Sep 17 00:00:00 2001 From: Florence Bockting Date: Wed, 22 Apr 2026 11:18:42 +0300 Subject: [PATCH 2/4] docs: leave original output in tutorial --- vignettes/flocker_tutorial.Rmd | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/vignettes/flocker_tutorial.Rmd b/vignettes/flocker_tutorial.Rmd index 2cb0c18..85b5967 100644 --- a/vignettes/flocker_tutorial.Rmd +++ b/vignettes/flocker_tutorial.Rmd @@ -471,18 +471,11 @@ model. loo_compare_flocker( list(rep_constant, rep_varying) ) -#> Warning messages: -#> 1: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. - -#> 2: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. - -#> model elpd_diff se_diff p_worse diag_diff diag_elpd -#> model2 0.0 0.0 NA 2 k_psis > 0.7 -#> model1 -169.5 17.2 1.00 1 k_psis > 0.7 - -#> Diagnostic flags present. -#> See ?`loo-glossary` (sections `diag_diff` and `diag_elpd`) -#> or https://mc-stan.org/loo/reference/loo-glossary.html. +#> Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. +#> Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. +#> elpd_diff se_diff +#> model2 0.0 0.0 +#> model1 -121.0 16.1 ``` Likewise, we can compare the four flavors of multi-season model that we fit @@ -496,11 +489,11 @@ performs best: loo_compare_flocker( list(multi_colex, multi_colex_eq, multi_auto, multi_auto_eq) ) -#> model elpd_diff se_diff p_worse diag_diff diag_elpd -#> model1 0.0 0.0 NA -#> model3 -8.0 4.1 0.98 -#> model2 -27.1 7.2 1.00 -#> model4 -32.9 7.8 1.00 +#> elpd_diff se_diff +#> model1 0.0 0.0 +#> model2 -16.5 6.2 +#> model3 -41.7 9.5 +#> model4 -57.5 10.8 ``` Flocker also provides the function `loo_flocker()` to return a table of From ff878f73a7ed8c56a21fa217a5f3311a9227487c Mon Sep 17 00:00:00 2001 From: Florence Bockting Date: Wed, 22 Apr 2026 11:19:01 +0300 Subject: [PATCH 3/4] chore: update NEWS.md to include changes wrt loo_compare() --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index f750359..68596f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,9 @@ * dramatically improved efficiency in certain post-processing functions for multiseason models * CI runs properly * backend hygiene improvements +* updated compatibility with upcoming changes to `loo_compare()` output + structure in the `loo` package (> 2.9.0), which now returns a data frame + instead of a matrix and includes additional diagnostic columns. # flocker 1.0-1 * fixed a bug that was throwing an uninformative error when making predictions in multiseason models where history_condition is TRUE From d3579cc463798e2e5b09f8d0ea732a1d116a032b Mon Sep 17 00:00:00 2001 From: Florence Bockting Date: Wed, 22 Apr 2026 11:35:40 +0300 Subject: [PATCH 4/4] docs: change loo_compare_flocker value to general compare.loo object --- R/loo.R | 2 +- man/loo_compare_flocker.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/loo.R b/R/loo.R index 77918f3..f592b96 100644 --- a/R/loo.R +++ b/R/loo.R @@ -63,7 +63,7 @@ loo_flocker_onefit <- function(x, thin = NULL) { #' @param thin specify the amount of thinning required. 1 or NULL results in no #' thinning, 2 retains every other value, 3 every third, etc. #' @param model_names An optional vector of names for the models. -#' @return a `compare.loo` matrix +#' @return a `compare.loo` object #' @export #' @examples #' \dontrun{ diff --git a/man/loo_compare_flocker.Rd b/man/loo_compare_flocker.Rd index d5faaa5..fec16d8 100644 --- a/man/loo_compare_flocker.Rd +++ b/man/loo_compare_flocker.Rd @@ -15,7 +15,7 @@ loo_compare_flocker(model_list, model_names = NULL, thin = NULL) thinning, 2 retains every other value, 3 every third, etc.} } \value{ -a `compare.loo` matrix +a `compare.loo` object } \description{ LOO comparisons for flocker models.