|
9 | 9 | @testset "standardize=false" begin
|
10 | 10 | m = turing_model(f, kidiq)
|
11 | 11 | chn = sample(seed!(123), m, NUTS(), MCMCThreads(), 2_000, 2)
|
12 |
| - @test summarystats(chn)[:α, :mean] ≈ 29.30 atol = 2.0 |
13 |
| - @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.533 atol = 0.2 |
14 |
| - @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.593 atol = 0.2 |
| 12 | + @test summarystats(chn)[:α, :mean] ≈ 31.80 atol = 2.0 |
| 13 | + @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.507 atol = 0.2 |
| 14 | + @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.22 atol = 0.2 |
15 | 15 | end
|
16 | 16 |
|
17 | 17 | @testset "standardize=true" begin
|
|
33 | 33 | @testset "explicit calling Normal" begin
|
34 | 34 | m = turing_model(f, kidiq; model=Normal)
|
35 | 35 | chn = sample(seed!(123), m, NUTS(), MCMCThreads(), 2_000, 2)
|
36 |
| - @test summarystats(chn)[:α, :mean] ≈ 29.30 atol = 2.0 |
37 |
| - @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.533 atol = 0.2 |
38 |
| - @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.593 atol = 0.2 |
| 36 | + @test summarystats(chn)[:α, :mean] ≈ 31.80 atol = 2.0 |
| 37 | + @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.507 atol = 0.2 |
| 38 | + @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.22 atol = 0.2 |
39 | 39 | end
|
40 | 40 | end
|
41 | 41 | @timed_testset "TDist Model" begin
|
42 | 42 | f = @formula(kid_score ~ mom_iq * mom_hs)
|
43 | 43 | @testset "standardize=false" begin
|
44 | 44 | m = turing_model(f, kidiq; model=TDist)
|
45 | 45 | chn = sample(seed!(123), m, NUTS(), MCMCThreads(), 2_000, 2)
|
46 |
| - @test summarystats(chn)[:α, :mean] ≈ 40.380 atol = 2.0 |
47 |
| - @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.478 atol = 0.2 |
48 |
| - @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.736 atol = 0.2 |
49 |
| - @test quantile(chn)[:ν, Symbol("50.0%")] ≈ 1.039 atol = 0.5 |
| 46 | + @test summarystats(chn)[:α, :mean] ≈ 33.31 atol = 2.0 |
| 47 | + @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.519 atol = 0.2 |
| 48 | + @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.340 atol = 0.2 |
| 49 | + @test quantile(chn)[:ν, Symbol("50.0%")] ≈ 2.787 atol = 0.5 |
50 | 50 | end
|
51 | 51 |
|
52 | 52 | @testset "custom_priors" begin
|
53 | 53 | priors = CustomPrior(Normal(), Normal(28, 5), Exponential(2))
|
54 | 54 | m = turing_model(f, kidiq; model=TDist, priors)
|
55 | 55 | chn = sample(seed!(123), m, NUTS(), MCMCThreads(), 2_000, 2)
|
56 |
| - @test summarystats(chn)[:α, :mean] ≈ 35.506 atol = 2.0 |
57 |
| - @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.522 atol = 0.2 |
58 |
| - @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.628 atol = 0.2 |
59 |
| - @test quantile(chn)[:ν, Symbol("50.0%")] ≈ 1.178 atol = 0.5 |
| 56 | + @test summarystats(chn)[:α, :mean] ≈ 28.565 atol = 2.0 |
| 57 | + @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.551 atol = 0.2 |
| 58 | + @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ 0.255 atol = 0.2 |
| 59 | + @test quantile(chn)[:ν, Symbol("50.0%")] ≈ 10.339 atol = 0.5 |
60 | 60 | end
|
61 | 61 | end
|
62 | 62 | @timed_testset "Bernoulli Model" begin
|
|
112 | 112 | priors = CustomPrior(Normal(), Normal(2, 5), Exponential(0.5))
|
113 | 113 | m = turing_model(f, roaches; model=NegativeBinomial, priors)
|
114 | 114 | chn = sample(seed!(123), m, NUTS(), MCMCThreads(), 2_000, 2)
|
115 |
| - @test summarystats(chn)[:α, :mean] ≈ 2.422 atol = 0.5 |
| 115 | + @test summarystats(chn)[:α, :mean] ≈ 2.401 atol = 0.5 |
116 | 116 | @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 0.013 atol = 0.2
|
117 |
| - @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ -0.732 atol = 0.2 |
| 117 | + @test quantile(chn)[Symbol("β[2]"), Symbol("50.0%")] ≈ -0.723 atol = 0.2 |
118 | 118 | @test quantile(chn)[:ϕ⁻, Symbol("50.0%")] ≈ 3.56 atol = 0.2
|
119 | 119 | end
|
120 | 120 | end
|
121 | 121 | @timed_testset "Hierarchical Model" begin
|
122 | 122 | f = @formula(y ~ (1 | cheese) + background)
|
123 | 123 | m = turing_model(f, cheese)
|
124 | 124 | chn = sample(seed!(123), m, NUTS(), MCMCThreads(), 2_000, 2)
|
125 |
| - @test summarystats(chn)[:α, :mean] ≈ 68.33 atol = 2.0 |
126 |
| - @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 6.928 atol = 0.2 |
127 |
| - @test summarystats(chn)[Symbol("zⱼ[1]"), :mean] ≈ 0.306 atol = 0.2 |
128 |
| - @test quantile(chn)[Symbol("zⱼ[2]"), Symbol("50.0%")] ≈ -1.422 atol = 0.5 |
| 125 | + @test summarystats(chn)[:α, :mean] ≈ 68.07 atol = 2.0 |
| 126 | + @test summarystats(chn)[Symbol("β[1]"), :mean] ≈ 6.60 atol = 0.2 |
| 127 | + @test summarystats(chn)[Symbol("zⱼ[1]"), :mean] ≈ 0.348 atol = 0.2 |
| 128 | + @test quantile(chn)[Symbol("zⱼ[2]"), Symbol("50.0%")] ≈ -1.376 atol = 0.5 |
129 | 129 | end
|
130 | 130 | @testset "Unsupported Model Likelihoods" begin
|
131 | 131 | @test_throws ArgumentError turing_model(@formula(y ~ x), nt_str; model=Binomial)
|
|
0 commit comments