Skip to content

Commit 1b6c3a7

Browse files
authored
Merge pull request #20 from florence-bockting/fix-loo_compare_output
Upcoming breaking changes in `loo_compare()` output
2 parents d8910ee + f1c560a commit 1b6c3a7

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# BayesERtools 0.2.5 (in development)
22

33
## Major changes
4-
4+
5+
* Updated compatibility with upcoming changes to `loo_compare()` output
6+
structure in the `loo` package (> 2.9.0), which now returns a data frame
7+
instead of a matrix and includes additional diagnostic columns.
8+
59
## Minor changes
610

711
* Allow manual breaks in `plot_er()` to control the position of the probability

R/dev_ermod_lin.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ dev_ermod_lin_cov_sel <- function(
489489
function(.x) loo(.x)
490490
)
491491
comp_exposures <- loo::loo_compare(l_loo_exposures)
492-
var_exposure <- rownames(comp_exposures)[[1]]
492+
if ("model" %in% colnames(comp_exposures)) {
493+
var_exposure <- comp_exposures$model[[1]]
494+
} else {
495+
var_exposure <- rownames(comp_exposures)[[1]]
496+
}
493497

494498
if (verbosity_level >= 1) {
495499
cli::cli_alert_info("The exposure metric selected was: {var_exposure}")

tests/testthat/test-dev_ermod_lin.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,17 @@ mod_mtcars <- dev_ermod_bin(
209209

210210
test_that("Exposure metrics selection", {
211211
expect_equal(extract_var_exposure(ermod_bin_exp_sel), "AUCss_1000")
212-
expect_equal(
213-
extract_exp_sel_comp(ermod_bin_exp_sel)[, 1],
214-
c(AUCss_1000 = 0.000000, Cmaxss = -0.6490312, Cminss = -2.7563957)
215-
)
212+
if ("model" %in% colnames(extract_exp_sel_comp(ermod_bin_exp_sel))) {
213+
expect_equal(
214+
extract_exp_sel_comp(ermod_bin_exp_sel)[, 2],
215+
c(0.000000, -0.6490312, -2.7563957)
216+
)
217+
} else {
218+
expect_equal(
219+
extract_exp_sel_comp(ermod_bin_exp_sel)[, 1],
220+
c(AUCss_1000 = 0.000000, Cmaxss = -0.6490312, Cminss = -2.7563957)
221+
)
222+
}
216223

217224
priors <- prior_summary(ermod_bin_exp_sel$l_mod_exposures[[2]])
218225
expect_equal(priors$prior$scale, 5)

tests/testthat/test-loo_kfold.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ if (.if_run_ex_eval_mod()) {
104104
})
105105

106106
test_that("kfold", {
107-
expect_gt(comp[[2, 1]], -0.5)
107+
if ("model" %in% colnames(comp)) {
108+
expect_gt(comp[[2, 2]], -0.5)
109+
} else {
110+
expect_gt(comp[[2, 1]], -0.5)
111+
}
108112
expect_equal(
109113
kfold_ermod_bin$estimates[, 1],
110114
c(elpd_kfold = -38.242947, p_kfold = 3.040264, kfoldic = 76.485893)

0 commit comments

Comments
 (0)