Skip to content

Commit 8d3d943

Browse files
Merge branch 'master' into add-ai-policy
2 parents 892c9c8 + 6cee125 commit 8d3d943

12 files changed

Lines changed: 515 additions & 143 deletions

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Authors@R: c(
1515
person("Juho", "Piironen", role = "ctb"),
1616
person("Bruno", "Nicenboim", role = "ctb"),
1717
person("Leevi", "Lindgren", role = "ctb"),
18-
person("Visruth", "Srimath Kandali", role = "ctb")
18+
person("Visruth", "Srimath Kandali", role = "ctb"),
19+
person("Florence", "Bockting", role = "ctb")
1920
)
2021
Maintainer: Jonah Gabry <jgabry@gmail.com>
2122
Description: Efficient approximate leave-one-out cross-validation (LOO)

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# loo (development version)
22

3+
## Breaking changes
4+
5+
* `loo_compare()` now returns a data frame instead of a matrix and has
6+
additional columns. Code that relies on matrix-specific behaviour will need to
7+
be updated accordingly by @jgabry, @avehtari, @florence-bockting in #300
8+
9+
## New features
10+
11+
* `loo_compare()` output now includes additional columns: `p_worse`,
12+
`diag_diff`, and `diag_elpd`, providing richer diagnostics for model
13+
comparison by @florence-bockting in #300
14+
315
# loo 2.9.0
416

517
* Avoid under and overflows in stacking by @avehtari in #273

R/loo-glossary.R

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,105 @@
153153
#' individual models due to correlation (i.e., if some observations are easier
154154
#' and some more difficult to predict for all models).
155155
#'
156+
#' @section `p_worse` (probability of worse predictive performance):
157+
#'
158+
#' `p_worse` is the estimated probability that a model has worse predictive
159+
#' performance than the best-ranked model in the comparison, based on the normal
160+
#' approximation to the uncertainty in `elpd_diff`. It is computed as
161+
#'
162+
#' p_worse = pnorm(0, elpd_diff, se_diff).
163+
#'
164+
#' The best-ranked model (the first row in the `loo_compare()` output, where
165+
#' `elpd_diff = 0`) always receives `NA`, since the comparison is defined
166+
#' relative to that model.
167+
#'
168+
#' Because models are ordered by `elpd_loo` before computing `p_worse`, all
169+
#' reported values are at least 0.5 by construction. A value close to 0.5
170+
#' indicates that the models are nearly indistinguishable in predictive
171+
#' performance and that the ranking could easily be reversed with different
172+
#' data. A value close to 1 indicates that the lower-ranked model is almost
173+
#' certainly worse. `p_worse` inherits all the limitations of `se_diff` and the
174+
#' normal approximation on which it is based. In particular, when `se_diff` is
175+
#' underestimated, `p_worse` will be estimated too close to 1, making a model
176+
#' appear more clearly worse than the data actually support. Conversely, when
177+
#' `elpd_diff` is biased due to an unreliable LOO approximation, `p_worse` can
178+
#' point in the wrong direction entirely. When any of these conditions are
179+
#' present, `diag_diff` or `diag_elpd` will be flagged in the `loo_compare()`
180+
#' output.
181+
#' For further guidance, see the sections below and the case study on
182+
#' [Uncertainty in Bayesian LOO-CV Model Comparison](
183+
#' https://users.aalto.fi/~ave/casestudies/LOO_uncertainty/loo_uncertainty.html).
184+
#'
185+
#' @section `diag_diff` (pairwise comparison diagnostics):
186+
#'
187+
#' `diag_diff` is a diagnostic column in the `loo_compare()` output for each
188+
#' model comparison against the current reference model. It flags conditions
189+
#' under which the normal approximation behind `se_diff` and `p_worse` is likely
190+
#' to be poorly calibrated. The column contains a short label when a condition
191+
#' is detected, and is empty otherwise.
192+
#'
193+
#' The column `diag_diff` currently flags two problems:
194+
#'
195+
#' ### `N < 100`
196+
#'
197+
#' When the number of observations is small, we may assume `se_diff` to be
198+
#' underestimated. As a rough heuristic one can multiply `se_diff` by 2 to
199+
#' make a more conservative estimate.
200+
#'
201+
#' ### `|elpd_diff| < 4`
202+
#'
203+
#' When `|elpd_diff|` is below 4, the models have very similar predictive
204+
#' performance. In this setting, Sivula et al. (2025) show that skewness in
205+
#' the error distribution can make the normal approximation for `se_diff`
206+
#' and `p_worse` miscalibrated, even for large N. In practice, this usually
207+
#' supports treating the models as predictively similar.
208+
#'
209+
#' ### Relation between `N < 100` and `|elpd_diff| < 4`
210+
#'
211+
#' The conditions flagged by `diag_diff` are not independent: they tend to
212+
#' co-occur, and when they do, some flags carry more information than others.
213+
#' `loo_compare()` therefore follows a priority hierarchy and shows only the
214+
#' most critical flag in the table output.
215+
#'
216+
#' The hierarchy is as follows:
217+
#'
218+
#' * **`N < 100` takes highest priority.** A small sample size undermines the
219+
#' reliability of `se_diff` by underestimating uncertainty. Because of this,
220+
#' even if `|elpd_diff| < 4` is also true for a comparison, the table will only
221+
#' show `N < 100`. The small sample size renders the `|elpd_diff| < 4`
222+
#' diagnostic less meaningful.
223+
#'
224+
#' * **`|elpd_diff| < 4` takes second priority.** When N >= 100 and the
225+
#' difference is small, the normal approximation is miscalibrated due to the
226+
#' skewness of the error distribution (Sivula et al., 2025). In this
227+
#' situation, `se_diff` exists and is not heavily biased in scale, but the
228+
#' shape of the approximation is wrong, making `p_worse` unreliable.
229+
#'
230+
#' For further guidance, see the case study on
231+
#' [Uncertainty in Bayesian LOO-CV Model Comparison](
232+
#' https://users.aalto.fi/~ave/casestudies/LOO_uncertainty/loo_uncertainty.html).
233+
#'
234+
#' @section `diag_elpd`:
235+
#'
236+
#' `diag_elpd` is a diagnostic column in the `loo_compare()` output that flags
237+
#' when the PSIS-LOO approximation for an individual model is unreliable. Unlike
238+
#' `diag_diff`, which concerns the *comparison* between models, `diag_elpd`
239+
#' concerns the quality of the `elpd_loo` estimate for each model individually.
240+
#' It contains a short text label when a problem is detected, and is empty
241+
#' otherwise.
242+
#'
243+
#' ### `K k_psis > t` (K observations with Pareto-k values > t)
244+
#'
245+
#' This label indicates that K observations for this model have Pareto-k values
246+
#' above the PSIS reliability threshold `t` used by `loo` for that fit. The
247+
#' threshold is sample-size dependent, and in many practical cases close to
248+
#' 0.7. When this flag appears, the PSIS approximation can be unreliable for
249+
#' those observations, and the resulting `elpd_loo` may be biased. Because
250+
#' `elpd_diff` is a direct difference of two models' `elpd_loo` values, bias in
251+
#' either model's estimate propagates directly into `elpd_diff` and `p_worse`.
252+
#' This is qualitatively different from the calibration issues flagged by
253+
#' `diag_diff`: here the estimate itself may be wrong, not just uncertain.
254+
#'
255+
#' See for further information on Pareto-k values the "Pareto k estimates"
256+
#' section.
156257
NULL

0 commit comments

Comments
 (0)