Skip to content

Commit a49c641

Browse files
author
Florence Bockting
committed
chore: add user message with link to loo-glossary in loo_compare outputx
1 parent c3ce77a commit a49c641

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

R/loo_compare.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ print.compare.loo <- function(x, ..., digits = 1, p_worse = TRUE) {
194194
)
195195
}
196196
print(x2, quote = FALSE, row.names = FALSE)
197+
198+
# show glossary for diagnostic flags
199+
has_diag <- any(nzchar(x[["diag_diff"]], keepNA = FALSE), na.rm = TRUE) ||
200+
any(nzchar(x[["diag_elpd"]], keepNA = FALSE), na.rm = TRUE)
201+
if (has_diag && p_worse) {
202+
message(
203+
"\nDiagnostic flags present. ",
204+
"See ?`loo-glossary` (sections `diag_diff` and `diag_elpd`) ",
205+
"or https://mc-stan.org/loo/reference/loo-glossary.html."
206+
)
207+
}
197208
invisible(x)
198209
}
199210

tests/testthat/_snaps/compare.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
model elpd_diff se_diff p_worse diag_diff diag_elpd
4848
model1 0.0 0.0 NA
4949
model2 -4.1 0.1 1.00 N < 100
50+
Message
51+
52+
Diagnostic flags present. See ?`loo-glossary` (sections `diag_diff` and `diag_elpd`) or https://mc-stan.org/loo/reference/loo-glossary.html.
5053

5154
---
5255

@@ -84,6 +87,9 @@
8487
model1 0.0 0.0 NA
8588
model2 -4.1 0.1 1.00 N < 100
8689
model3 -16.1 0.2 1.00 N < 100
90+
Message
91+
92+
Diagnostic flags present. See ?`loo-glossary` (sections `diag_diff` and `diag_elpd`) or https://mc-stan.org/loo/reference/loo-glossary.html.
8793

8894
# compare returns expected result (3 models)
8995

0 commit comments

Comments
 (0)