Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Jul 3, 2024
2 parents 5794eff + b1f7a5a commit 3bc38c9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 31 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 2.7.0
Date: 2024-02-24 21:45:11 UTC
SHA: e1f9a29e68f937d992861d40df7e48421204e05b
Version: 2.8.0
Date: 2024-07-03 16:27:12 UTC
SHA: 23e68bf5fb8aa9d000358f3bbbf52cf7ee92a99c
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: loo
Type: Package
Title: Efficient Leave-One-Out Cross-Validation and WAIC for Bayesian Models
Version: 2.7.0
Date: 2024-02-24
Version: 2.8.0
Date: 2024-07-03
Authors@R: c(person("Aki", "Vehtari", email = "[email protected]", role = c("aut")),
person("Jonah", "Gabry", email = "[email protected]", role = c("cre", "aut")),
person("Mans", "Magnusson", role = c("aut")),
person("Måns", "Magnusson", role = c("aut")),
person("Yuling", "Yao", role = c("aut")),
person("Paul-Christian", "Bürkner", role = c("aut")),
person("Topi", "Paananen", role = c("aut")),
Expand Down Expand Up @@ -53,5 +53,5 @@ Suggests:
VignetteBuilder: knitr
Encoding: UTF-8
SystemRequirements: pandoc (>= 1.12.3), pandoc-citeproc
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
40 changes: 27 additions & 13 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
# loo 2.8.0

* make E_loo Pareto-k diagnostic more robust by @avehtari in #251
* update psis paper reference by @avehtari in #252
* update PSIS references in vignettes by @jgabry in #254
* fix loo_moment_match p_loo computation by @avehtari in #257
* fix loo_moment_matching NaN issue by @avehtari in #259
* catch Stan log_prob exceptions inside moment matching by @avehtari in #262
* Fix E_loo_khat error when posterior::pareto_khat returns NA by @jgabry in #264
* update psis ref + some minor typo fixes by @avehtari in #266
* update PSIS ref + link to Nabiximols study for Jacobian correction by @avehtari in #267
* Fix issue with pareto_khat output no longer being a list by @n-kall in #269
* fix equations in loo-glossary by @avehtari in #268

# loo 2.7.0

### Major changes

* __New sample size specific diagnostic threshold for Pareto `k`__. The pre-2022 version
of the [PSIS paper](https://arxiv.org/abs/1507.02646) recommended diagnostic
thresholds of
`k < 0.5 "good"`, `0.5 <= k < 0.7 "ok"`,
`0.7 <= k < 1 "bad"`, `k>=1 "very bad"`.
The 2022 revision of the PSIS paper now recommends
`k < min(1 - 1/log10(S), 0.7) "good"`, `min(1 - 1/log10(S), 0.7) <= k < 1 "bad"`,
`k > 1 "very bad"`, where `S` is the sample size.
thresholds of
`k < 0.5 "good"`, `0.5 <= k < 0.7 "ok"`,
`0.7 <= k < 1 "bad"`, `k>=1 "very bad"`.
The 2022 revision of the PSIS paper now recommends
`k < min(1 - 1/log10(S), 0.7) "good"`, `min(1 - 1/log10(S), 0.7) <= k < 1 "bad"`,
`k > 1 "very bad"`, where `S` is the sample size.
There is now one fewer diagnostic threshold (`"ok"` has been removed), and the
most important threshold now depends on the sample size `S`. With sample sizes
`100`, `320`, `1000`, `2200`, `10000` the sample size specific part
`100`, `320`, `1000`, `2200`, `10000` the sample size specific part
`1 - 1/log10(S)` corresponds to thresholds of `0.5`, `0.6`, `0.67`, `0.7`, `0.75`.
Even if the sample size grows, the bias in the PSIS estimate dominates if
`0.7 <= k < 1`, and thus the diagnostic threshold for good is capped at
`0.7` (if `k > 1`, the mean does not exist and bias is not a valid measure).
Even if the sample size grows, the bias in the PSIS estimate dominates if
`0.7 <= k < 1`, and thus the diagnostic threshold for good is capped at
`0.7` (if `k > 1`, the mean does not exist and bias is not a valid measure).
The new recommended thresholds are based on more careful bias-variance analysis
of PSIS based on truncated Pareto sums theory. For those who use the Stan
default 4000 posterior draws, the `0.7` threshold will be roughly the same, but
there will be fewer warnings as there will be no diagnostic message for `0.5 <=
k < 0.7`. Those who use smaller sample sizes may see diagnostic messages with a
threshold less than `0.7`, and they can simply increase the sample size to about
`2200` to get the threshold to `0.7`.
`2200` to get the threshold to `0.7`.

* __No more warnings if the `r_eff` argument is not provided__, and the
default is now `r_eff = 1`. The summary print output showing MCSE and ESS now
Expand Down Expand Up @@ -55,10 +69,10 @@ only when MCSE and ESS values are shown.
* fix R cmd check notes by @jgabry in #242



# loo 2.6.0

### New features
### New features

* New `loo_predictive_metric()` function for computing estimates of leave-one-out
predictive metrics: mean absolute error, mean squared error and root mean
Expand Down
20 changes: 16 additions & 4 deletions R/E_loo.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,23 @@ E_loo_khat.matrix <- function(x, psis_object, log_ratios, ...) {
.E_loo_khat_i <- function(x_i, log_ratios_i, tail_len_i) {
h_theta <- x_i
r_theta <- exp(log_ratios_i - max(log_ratios_i))
khat_r <- posterior::pareto_khat(r_theta, tail = "right", ndraws_tail = tail_len_i)$khat
if (is.null(x_i)) {
khat_r <- posterior::pareto_khat(r_theta, tail = "right", ndraws_tail = tail_len_i)
if (is.list(khat_r)) { # retain compatiblity with older posterior that returned a list
khat_r <- khat_r$khat
}
if (is.null(x_i) || is_constant(x_i) || length(unique(x_i))==2 ||
anyNA(x_i) || any(is.infinite(x_i))) {
khat_r
} else {
khat_hr <- posterior::pareto_khat(h_theta * r_theta, tail = "both", ndraws_tail = tail_len_i)$khat
max(khat_hr, khat_r)
khat_hr <- posterior::pareto_khat(h_theta * r_theta, tail = "both", ndraws_tail = tail_len_i)
if (is.list(khat_hr)) { # retain compatiblity with older posterior that returned a list
khat_hr <- khat_hr$khat
}
if (is.na(khat_hr) && is.na(khat_r)) {
k <- NA
} else {
k <- max(khat_hr, khat_r, na.rm=TRUE)
}
k
}
}
6 changes: 3 additions & 3 deletions R/loo-glossary.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@
#' is usually negligible. Thinning of MCMC draws can be used to improve
#' the ratio ESS/S.
#'
#' * If \eqn{k < min(1 - 1 / log10(S), 0.7)}, where \eqn{S} is the
#' * If \eqn{k < \min(1 - 1 / \log_{10}(S), 0.7)}, where \eqn{S} is the
#' sample size, the PSIS estimate and the corresponding Monte
#' Carlo standard error estimate are reliable.
#'
#' * If \eqn{1 - 1 / log10(S) <= k < 0.7}, the PSIS estimate and the
#' * If \eqn{1 - 1 / \log_{10}(S) <= k < 0.7}, the PSIS estimate and the
#' corresponding Monte Carlo standard error estimate are not
#' reliable, but increasing the (effective) sample size \eqn{S} above
#' 2200 may help (this will increase the sample size specific
#' threshold \eqn{(1 - 1 / log10(2200) > 0.7} and then the bias specific
#' threshold \eqn{(1 - 1 / \log_{10}(2200) > 0.7} and then the bias specific
#' threshold 0.7 dominates).
#'
#' * If \eqn{0.7 <= k < 1}, the PSIS estimate and the corresponding Monte
Expand Down
6 changes: 3 additions & 3 deletions man/loo-glossary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/loo-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3bc38c9

Please sign in to comment.