Skip to content

Commit 7f072f4

Browse files
fix bootstrap tests
1 parent 58cdb0f commit 7f072f4

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

test/examples/helper.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using LinearAlgebra: norm
2+
using Suppressor
23

34
function is_extended_tests()
45
return lowercase(get(ENV, "JULIA_EXTENDED_TESTS", "false")) == "true"
@@ -144,19 +145,23 @@ function test_bootstrap(
144145
compare_bs = true,
145146
rtol_bs = 0.1,
146147
n_boot = 500)
147-
se_bs = se_bootstrap(model_fit, spec; n_boot = n_boot)
148-
# hessian and bootstrap se are close
149-
if compare_hessian
150-
se_he = se_hessian(model_fit)
151-
@test isapprox(se_bs, se_he, rtol = rtol_hessian)
152-
end
153-
# se_bootstrap and bootstrap |> se are close
154-
if compare_bs
155-
bs_samples = bootstrap(model_fit, spec; n_boot = n_boot)
156-
@test bs_samples[:n_converged] >= 0.95*n_boot
157-
bs_samples = cat(bs_samples[:samples][BitVector(bs_samples[:converged])]..., dims = 2)
158-
se_bs_2 = sqrt.(var(bs_samples, corrected = false, dims = 2))
159-
@test isapprox(se_bs_2, se_bs, rtol = rtol_bs)
148+
@testset rng = Random.seed!(32432) "bootstrap" begin
149+
se_bs = @suppress se_bootstrap(model_fit, spec; n_boot = n_boot)
150+
# hessian and bootstrap se are close
151+
if compare_hessian
152+
se_he = @suppress se_hessian(model_fit)
153+
#println(maximum(abs.(se_he - se_bs)))
154+
@test isapprox(se_bs, se_he, rtol = rtol_hessian)
155+
end
156+
# se_bootstrap and bootstrap |> se are close
157+
if compare_bs
158+
bs_samples = bootstrap(model_fit, spec; n_boot = n_boot)
159+
@test bs_samples[:n_converged] >= 0.95*n_boot
160+
bs_samples = cat(bs_samples[:samples][BitVector(bs_samples[:converged])]..., dims = 2)
161+
se_bs_2 = sqrt.(var(bs_samples, corrected = false, dims = 2))
162+
#println(maximum(abs.(se_bs_2 - se_bs)))
163+
@test isapprox(se_bs_2, se_bs, rtol = rtol_bs)
164+
end
160165
end
161166
end
162167

@@ -168,7 +173,7 @@ function smoketest_bootstrap(model_fit, spec; n_boot = 5)
168173
end
169174

170175
function smoketest_CI_z(model_fit, partable)
171-
se_he = se_hessian(model_fit)
176+
se_he = @suppress se_hessian(model_fit)
172177
normal_CI!(partable, model_fit, se_he)
173178
z_test!(partable, model_fit, se_he)
174179
end

0 commit comments

Comments
 (0)