From b962b631a39cc310588cc38f7567de8b5283ce3f Mon Sep 17 00:00:00 2001 From: Aki Vehtari Date: Fri, 20 Dec 2024 14:25:10 +0200 Subject: [PATCH] use the same equation in ess_sd as in mcse_sd --- R/convergence.R | 5 ++++- tests/testthat/test-convergence.R | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/convergence.R b/R/convergence.R index f76ef94a..a96a4eca 100644 --- a/R/convergence.R +++ b/R/convergence.R @@ -357,7 +357,10 @@ ess_sd <- function(x, ...) UseMethod("ess_sd") #' @rdname ess_sd #' @export ess_sd.default <- function(x, ...) { - .ess(.split_chains(abs(x-mean(x)))) + # var/sd are not a simple expectation of g(X), e.g. variance + # has (X-E[X])^2. The following ESS is based on a relevant quantity + # in the computation and is empirically a good choice. + .ess(.split_chains((x-mean(x))^2)) } #' @rdname ess_sd diff --git a/tests/testthat/test-convergence.R b/tests/testthat/test-convergence.R index 96194d8d..0da94f5b 100644 --- a/tests/testthat/test-convergence.R +++ b/tests/testthat/test-convergence.R @@ -19,7 +19,7 @@ test_that("ess diagnostics return reasonable values", { expect_true(ess > 250 & ess < 310) ess <- ess_sd(tau) - expect_true(ess > 250 & ess < 310) + expect_true(ess > 230 & ess < 280) ess <- ess_bulk(tau) expect_true(ess > 230 & ess < 280)