Skip to content

Commit 2769ffb

Browse files
sethaxendevmotion
andauthored
Make MCSE for constant arrays always return a NaN (#128)
* Make mcse return NaN for constant arrays * Add missing tests * Increment patch number * Increment patch number * Update src/mcse.jl Co-authored-by: David Widmann <[email protected]> * Require at least Julia v1.8 * Use allequal * Run CI on lowest supported Julia version * Fix determination of nan type * Update version specifiers in CI workflow Co-authored-by: David Widmann <[email protected]> --------- Co-authored-by: David Widmann <[email protected]>
1 parent 877214d commit 2769ffb

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

.github/workflows/CI.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
version:
17-
- '1.6'
17+
- 'min'
18+
- 'lts'
1819
- '1'
19-
- 'nightly'
20+
- 'pre'
2021
os:
2122
- ubuntu-latest
2223
arch:

Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MCMCDiagnosticTools"
22
uuid = "be115224-59cd-429b-ad48-344e309966f0"
33
authors = ["David Widmann", "Seth Axen"]
4-
version = "0.3.11"
4+
version = "0.3.12"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -44,7 +44,7 @@ StatsBase = "0.33.7, 0.34"
4444
StatsFuns = "1"
4545
Tables = "1.11"
4646
Test = "1.6"
47-
julia = "1.6"
47+
julia = "1.8"
4848

4949
[extras]
5050
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

src/mcse.jl

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ end
9595

9696
function _mcse_quantile(x, p, Seff)
9797
Seff === missing && return missing
98+
if isnan(Seff)
99+
return oftype(oneunit(eltype(x)) / 1, NaN)
100+
end
98101
S = length(x)
99102
# quantile error distribution is asymptotically normal; estimate σ (mcse) with 2
100103
# quadrature points: xl and xu, chosen as quantiles so that xu - xl = 2σ
@@ -133,6 +136,10 @@ function _mcse_sbm(f, x, batch_size)
133136
any(x -> x === missing, x) && return missing
134137
n = length(x)
135138
i1 = firstindex(x)
139+
if allequal(x)
140+
y1 = f(view(x, i1:(i1 + batch_size - 1)))
141+
return oftype(y1, NaN)
142+
end
136143
v = Statistics.var(
137144
f(view(x, i:(i + batch_size - 1))) for i in i1:(i1 + n - batch_size);
138145
corrected=false,

test/mcse.jl

+17
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ using StatsBase
8383
end
8484
end
8585

86+
@testset "mcse for scalar array is always a NaN" begin
87+
x = ones(100)
88+
@testset for kind in [
89+
mean,
90+
median,
91+
std,
92+
mad,
93+
# uses sbm
94+
x -> mean(x),
95+
x -> median(x),
96+
x -> std(x),
97+
x -> mad(x),
98+
]
99+
@test isnan(mcse(x; kind))
100+
end
101+
end
102+
86103
@testset "estimand is within interval defined by MCSE estimate" begin
87104
# we check the MCSE estimates by simulating uncorrelated, correlated, and
88105
# anticorrelated chains, mapping the draws to a target distribution, computing the

0 commit comments

Comments
 (0)