From e6b4dbbfded660efa8657170130a14843fe1934d Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Sun, 17 Nov 2024 17:32:13 +0100 Subject: [PATCH 01/10] Make mcse return NaN for constant arrays --- src/mcse.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mcse.jl b/src/mcse.jl index 3bc12728..16c2867a 100644 --- a/src/mcse.jl +++ b/src/mcse.jl @@ -94,7 +94,7 @@ function _mcse( end function _mcse_quantile(x, p, Seff) - Seff === missing && return missing + (Seff === missing || isnan(Seff)) && return Seff S = length(x) # quantile error distribution is asymptotically normal; estimate σ (mcse) with 2 # quadrature points: xl and xu, chosen as quantiles so that xu - xl = 2σ @@ -133,6 +133,10 @@ function _mcse_sbm(f, x, batch_size) any(x -> x === missing, x) && return missing n = length(x) i1 = firstindex(x) + if all(==(first(x)), x) + y1 = f(view(x, i1:(i1 + batch_size - 1))) + return oftype(y1, NaN) + end v = Statistics.var( f(view(x, i:(i + batch_size - 1))) for i in i1:(i1 + n - batch_size); corrected=false, From 341399b4bf22ef66a24f34aabb2ee1042b2f5b28 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Sun, 17 Nov 2024 17:32:25 +0100 Subject: [PATCH 02/10] Add missing tests --- test/mcse.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/mcse.jl b/test/mcse.jl index 4a8c2e48..35a7d408 100644 --- a/test/mcse.jl +++ b/test/mcse.jl @@ -83,6 +83,23 @@ using StatsBase end end + @testset "mcse for scalar array is always a NaN" begin + x = ones(100) + @testset for kind in [ + mean, + median, + std, + mad, + # uses sbm + x -> mean(x), + x -> median(x), + x -> std(x), + x -> mad(x), + ] + @test isnan(mcse(x; kind)) + end + end + @testset "estimand is within interval defined by MCSE estimate" begin # we check the MCSE estimates by simulating uncorrelated, correlated, and # anticorrelated chains, mapping the draws to a target distribution, computing the From 72f4d3bf68e8eb28ab78f54be7f40745306b2a79 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Sun, 17 Nov 2024 17:32:42 +0100 Subject: [PATCH 03/10] Increment patch number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f78d6d38..3b92c26f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MCMCDiagnosticTools" uuid = "be115224-59cd-429b-ad48-344e309966f0" authors = ["David Widmann", "Seth Axen"] -version = "0.3.10" +version = "0.3.11" [deps] AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" From d32fa1246628fce9a6c787abf2953f3e69204ebf Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Sun, 17 Nov 2024 22:49:41 +0100 Subject: [PATCH 04/10] Increment patch number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 2759d394..699cf87d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MCMCDiagnosticTools" uuid = "be115224-59cd-429b-ad48-344e309966f0" authors = ["David Widmann", "Seth Axen"] -version = "0.3.11" +version = "0.3.12" [deps] AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" From cfa56e489761499d2a08f5ee04cbc1f38eb310b9 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Sun, 17 Nov 2024 22:58:04 +0100 Subject: [PATCH 05/10] Update src/mcse.jl Co-authored-by: David Widmann --- src/mcse.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mcse.jl b/src/mcse.jl index 16c2867a..7bfce41c 100644 --- a/src/mcse.jl +++ b/src/mcse.jl @@ -94,7 +94,11 @@ function _mcse( end function _mcse_quantile(x, p, Seff) - (Seff === missing || isnan(Seff)) && return Seff + Seff === missing && return missing + if isnan(Seff) + T = eltype(x) / 1 + return T(NaN) + end S = length(x) # quantile error distribution is asymptotically normal; estimate σ (mcse) with 2 # quadrature points: xl and xu, chosen as quantiles so that xu - xl = 2σ From a24bb4806c816580cf3bb208c0bc73a4bcbec979 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Mon, 18 Nov 2024 13:21:10 +0100 Subject: [PATCH 06/10] Require at least Julia v1.8 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 699cf87d..2673c385 100644 --- a/Project.toml +++ b/Project.toml @@ -44,7 +44,7 @@ StatsBase = "0.33.7, 0.34" StatsFuns = "1" Tables = "1.11" Test = "1.6" -julia = "1.6" +julia = "1.8" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" From 492791e092a2b668a8d319710a10cd4826c858a6 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Mon, 18 Nov 2024 13:21:16 +0100 Subject: [PATCH 07/10] Use allequal --- src/mcse.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mcse.jl b/src/mcse.jl index 7bfce41c..567db066 100644 --- a/src/mcse.jl +++ b/src/mcse.jl @@ -137,7 +137,7 @@ function _mcse_sbm(f, x, batch_size) any(x -> x === missing, x) && return missing n = length(x) i1 = firstindex(x) - if all(==(first(x)), x) + if allequal(x) y1 = f(view(x, i1:(i1 + batch_size - 1))) return oftype(y1, NaN) end From 71181127e87850023d8a1b8130ab6482eb724051 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Mon, 18 Nov 2024 13:22:16 +0100 Subject: [PATCH 08/10] Run CI on lowest supported Julia version --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 14f5eaa1..2e33787b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: version: - - '1.6' + - '1.8' - '1' - 'nightly' os: From 44ed3073cd796c5b72f563647100ec568f52d70f Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Mon, 18 Nov 2024 13:25:09 +0100 Subject: [PATCH 09/10] Fix determination of nan type --- src/mcse.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mcse.jl b/src/mcse.jl index 567db066..c2b41886 100644 --- a/src/mcse.jl +++ b/src/mcse.jl @@ -96,8 +96,7 @@ end function _mcse_quantile(x, p, Seff) Seff === missing && return missing if isnan(Seff) - T = eltype(x) / 1 - return T(NaN) + return oftype(oneunit(eltype(x)) / 1, NaN) end S = length(x) # quantile error distribution is asymptotically normal; estimate σ (mcse) with 2 From b73fae28c9481adf8e42688ad3a54df6b0ab6eb7 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Mon, 18 Nov 2024 15:00:30 +0100 Subject: [PATCH 10/10] Update version specifiers in CI workflow Co-authored-by: David Widmann --- .github/workflows/CI.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2e33787b..d9800b5d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,9 +14,10 @@ jobs: fail-fast: false matrix: version: - - '1.8' + - 'min' + - 'lts' - '1' - - 'nightly' + - 'pre' os: - ubuntu-latest arch: