Skip to content

Commit 82a1b9e

Browse files
committed
Swapped more print tests to snaps
1 parent 23f2117 commit 82a1b9e

File tree

12 files changed

+327
-99
lines changed

12 files changed

+327
-99
lines changed

tests/testthat/_snaps/compare.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# loo_compare returns expected results (2 models)
22

3-
WAoAAAACAAQFAAACAwAAAAMOAAAAEAAAAAAAAAAAwBA6U1+cRe4AAAAAAAAAAD+2ake0LxMB
3+
Code
4+
print(comp1)
5+
Output
6+
elpd_diff se_diff
7+
model1 0.0 0.0
8+
model2 0.0 0.0
9+
10+
---
11+
12+
Code
13+
print(comp2)
14+
Output
15+
elpd_diff se_diff
16+
model1 0.0 0.0
17+
model2 -4.1 0.1
18+
19+
---
20+
21+
WAoAAAACAAQFAgACAwAAAAMOAAAAEAAAAAAAAAAAwBA6U1+cRe4AAAAAAAAAAD+2ake0LxMB
422
wFTh8N3JQljAVeWWE8MGuUARCD2zEXBfQBEalRIN2T9ACijAYdW5U0AmZ5XrANCKP/H9Zexy
523
814/8ZtgnG1nx0Bk4fDdyUJYQGXllhPDBrlAIQg9sxFwX0AhGpUSDdk/AAAEAgAAAAEABAAJ
624
AAAAA2RpbQAAAA0AAAACAAAAAgAAAAgAAAQCAAAAAQAEAAkAAAAIZGltbmFtZXMAAAATAAAA
@@ -12,8 +30,18 @@
1230

1331
# loo_compare returns expected result (3 models)
1432

15-
WAoAAAACAAQFAAACAwAAAAMOAAAAGAAAAAAAAAAAwBA6U1+cRe7AMA3KkbYEGAAAAAAAAAAA
16-
P7ZqR7QvEwE/y6/t4TTtXsBU4fDdyUJYwFXllhPDBrnAWOVjgjbDYkARCD2zEXBfQBEalRIN
33+
Code
34+
print(comp1)
35+
Output
36+
elpd_diff se_diff
37+
model1 0.0 0.0
38+
model2 -4.1 0.1
39+
model3 -16.1 0.2
40+
41+
---
42+
43+
WAoAAAACAAQFAgACAwAAAAMOAAAAGAAAAAAAAAAAwBA6U1+cRe7AMA3KkbYEGAAAAAAAAAAA
44+
P7ZqR7QvEwE/y6/t4TTtYMBU4fDdyUJYwFXllhPDBrnAWOVjgjbDYkARCD2zEXBfQBEalRIN
1745
2T9AEPIF3GigE0AKKMBh1blTQCZnlesA0IpAQcjYUhrdCj/x/WXscvNeP/GbYJxtZ8c/8YDQ
1846
kmfJX0Bk4fDdyUJYQGXllhPDBrlAaOVjgjbDYkAhCD2zEXBfQCEalRIN2T9AIPIF3GigEwAA
1947
BAIAAAABAAQACQAAAANkaW0AAAANAAAAAgAAAAMAAAAIAAAEAgAAAAEABAAJAAAACGRpbW5h
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# print_dims.kfold works
2+
3+
Code
4+
print_dims(xx)
5+
Output
6+
Based on 17-fold cross-validation.
7+
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Test the vignette
2+
3+
Code
4+
print(looss_1)
5+
Output
6+
7+
Computed from 4000 by 100 subsampled log-likelihood
8+
values from 3020 total observations.
9+
10+
Estimate SE subsampling SE
11+
elpd_loo -1968.5 15.6 0.3
12+
p_loo 3.1 0.1 0.4
13+
looic 3936.9 31.2 0.6
14+
------
15+
MCSE of elpd_loo is 0.0.
16+
MCSE and ESS estimates assume independent draws (r_eff=1).
17+
18+
All Pareto k estimates are good (k < 0.7).
19+
See help('pareto-k-diagnostic') for details.
20+
21+
---
22+
23+
Code
24+
print(looss_1b)
25+
Output
26+
27+
Computed from 4000 by 200 subsampled log-likelihood
28+
values from 3020 total observations.
29+
30+
Estimate SE subsampling SE
31+
elpd_loo -1968.3 15.6 0.2
32+
p_loo 3.2 0.1 0.4
33+
looic 3936.7 31.2 0.5
34+
------
35+
MCSE of elpd_loo is 0.0.
36+
MCSE and ESS estimates assume independent draws (r_eff=1).
37+
38+
All Pareto k estimates are good (k < 0.7).
39+
See help('pareto-k-diagnostic') for details.
40+
41+
---
42+
43+
Code
44+
print(aploo_1)
45+
Output
46+
47+
Computed from 2000 by 3020 log-likelihood matrix.
48+
49+
Estimate SE
50+
elpd_loo -1968.4 15.6
51+
p_loo 3.2 0.2
52+
looic 3936.8 31.2
53+
------
54+
Posterior approximation correction used.
55+
MCSE of elpd_loo is 0.0.
56+
MCSE and ESS estimates assume independent draws (r_eff=1).
57+
58+
All Pareto k estimates are good (k < 0.7).
59+
See help('pareto-k-diagnostic') for details.
60+
61+
---
62+
63+
Code
64+
print(looapss_1)
65+
Output
66+
67+
Computed from 2000 by 100 subsampled log-likelihood
68+
values from 3020 total observations.
69+
70+
Estimate SE subsampling SE
71+
elpd_loo -1968.2 15.6 0.4
72+
p_loo 2.9 0.1 0.5
73+
looic 3936.4 31.1 0.8
74+
------
75+
Posterior approximation correction used.
76+
MCSE of elpd_loo is 0.0.
77+
MCSE and ESS estimates assume independent draws (r_eff=1).
78+
79+
All Pareto k estimates are good (k < 0.7).
80+
See help('pareto-k-diagnostic') for details.
81+
82+
---
83+
84+
Code
85+
print(looss_2)
86+
Output
87+
88+
Computed from 4000 by 100 subsampled log-likelihood
89+
values from 3020 total observations.
90+
91+
Estimate SE subsampling SE
92+
elpd_loo -1952.0 16.2 0.2
93+
p_loo 2.6 0.1 0.3
94+
looic 3903.9 32.4 0.4
95+
------
96+
MCSE of elpd_loo is 0.0.
97+
MCSE and ESS estimates assume independent draws (r_eff=1).
98+
99+
All Pareto k estimates are good (k < 0.7).
100+
See help('pareto-k-diagnostic') for details.
101+
102+
---
103+
104+
Code
105+
print(comp)
106+
Output
107+
elpd_diff se_diff subsampling_se_diff
108+
model2 0.0 0.0 0.0
109+
model1 16.5 22.5 0.4
110+
111+
---
112+
113+
Code
114+
print(comp)
115+
Output
116+
elpd_diff se_diff subsampling_se_diff
117+
model2 0.0 0.0 0.0
118+
model1 16.1 4.4 0.1
119+
120+
---
121+
122+
Code
123+
print(comp2)
124+
Output
125+
elpd_diff se_diff subsampling_se_diff
126+
model2 0.0 0.0 0.0
127+
model1 16.3 4.4 0.1
128+
129+
---
130+
131+
Code
132+
print(comp3)
133+
Output
134+
elpd_diff se_diff subsampling_se_diff
135+
model2 0.0 0.0 0.0
136+
model1 16.5 4.4 0.3
137+
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
# loo_model_weights (stacking and pseudo-BMA) gives expected result
22

3-
WAoAAAACAAQFAAACAwAAAAAOAAAAAz/KEXngFjO6P+l7oXTIUDU+YzIi3AAAAA==
3+
WAoAAAACAAQFAgACAwAAAAAOAAAAAz/KEXnf1DM9P+l7oXTYyi4+YzIpAwAAAA==
44

55
---
66

7-
WAoAAAACAAQFAAACAwAAAAAOAAAAAz+xA6UGtqDFP+3eFS5zKzY/J2MLYAsc4w==
7+
Code
8+
print(w1)
9+
Output
10+
Method: stacking
11+
------
12+
weight
13+
model1 0.204
14+
model2 0.796
15+
model3 0.000
16+
17+
---
18+
19+
WAoAAAACAAQFAgACAwAAAAAOAAAAAz+xA6UGtqDDP+3eFS5zKzY/J2MLYAsc4A==
20+
21+
---
22+
23+
Code
24+
print(w2)
25+
Output
26+
Method: pseudo-BMA+ with Bayesian bootstrap
27+
------
28+
weight
29+
model1 0.066
30+
model2 0.933
31+
model3 0.000
32+
33+
---
34+
35+
Code
36+
print(w3)
37+
Output
38+
Method: pseudo-BMA
39+
------
40+
weight
41+
model1 0.000
42+
model2 1.000
43+
model3 0.000
844

tests/testthat/_snaps/print_plot.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,67 @@
1+
# print.waic output is ok
2+
3+
Code
4+
print(waic1)
5+
Output
6+
7+
Computed from 1000 by 32 log-likelihood matrix.
8+
9+
Estimate SE
10+
elpd_waic -83.5 4.3
11+
p_waic 3.3 1.1
12+
waic 167.1 8.5
13+
14+
3 (9.4%) p_waic estimates greater than 0.4. We recommend trying loo instead.
15+
16+
# print.psis_loo and print.psis output ok
17+
18+
Code
19+
print(psis1)
20+
Output
21+
Computed from 1000 by 32 log-weights matrix.
22+
MCSE and ESS estimates assume independent draws (r_eff=1).
23+
24+
All Pareto k estimates are good (k < 0.67).
25+
See help('pareto-k-diagnostic') for details.
26+
27+
---
28+
29+
Code
30+
print(loo1)
31+
Output
32+
33+
Computed from 1000 by 32 log-likelihood matrix.
34+
35+
Estimate SE
36+
elpd_loo -83.6 4.3
37+
p_loo 3.3 1.2
38+
looic 167.2 8.6
39+
------
40+
MCSE of elpd_loo is 0.1.
41+
MCSE and ESS estimates assume independent draws (r_eff=1).
42+
43+
All Pareto k estimates are good (k < 0.67).
44+
See help('pareto-k-diagnostic') for details.
45+
46+
---
47+
48+
Code
49+
print(loo1_r_eff)
50+
Output
51+
52+
Computed from 1000 by 32 log-likelihood matrix.
53+
54+
Estimate SE
55+
elpd_loo -83.6 4.3
56+
p_loo 3.3 1.2
57+
looic 167.2 8.6
58+
------
59+
MCSE of elpd_loo is 0.1.
60+
MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]).
61+
62+
All Pareto k estimates are good (k < 0.67).
63+
See help('pareto-k-diagnostic') for details.
64+
165
# mcse_loo extractor gives correct value
266

367
WAoAAAACAAQFAAACAwAAAAAOAAAAAT+2J8YDcP5s

tests/testthat/_snaps/tisis.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,31 @@
1111
All Pareto k estimates are good (k < 0.67).
1212
See help('pareto-k-diagnostic') for details.
1313

14+
# tis_loo and sis_loo are returned
15+
16+
Code
17+
print(loo_tis)
18+
Output
19+
20+
Computed from 1000 by 32 log-likelihood matrix using tis_loo .
21+
22+
Estimate SE
23+
elpd_loo -83.6 4.3
24+
p_loo 3.3 1.2
25+
looic 167.2 8.6
26+
------
27+
28+
---
29+
30+
Code
31+
print(loo_sis)
32+
Output
33+
34+
Computed from 1000 by 32 log-likelihood matrix using sis_loo .
35+
36+
Estimate SE
37+
elpd_loo -83.6 4.3
38+
p_loo 3.3 1.2
39+
looic 167.2 8.6
40+
------
41+

tests/testthat/test_compare.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ test_that("loo_compare returns expected results (2 models)", {
8989
expect_s3_class(comp1, "compare.loo")
9090
expect_equal(colnames(comp1), comp_colnames)
9191
expect_equal(rownames(comp1), c("model1", "model2"))
92-
expect_output(print(comp1), "elpd_diff")
92+
expect_snapshot(print(comp1))
9393
expect_equal(comp1[1:2, 1], c(0, 0), ignore_attr = TRUE)
9494
expect_equal(comp1[1:2, 2], c(0, 0), ignore_attr = TRUE)
9595

9696
comp2 <- loo_compare(w1, w2)
9797
expect_s3_class(comp2, "compare.loo")
9898
expect_equal(colnames(comp2), comp_colnames)
99+
expect_snapshot(print(comp2))
99100

100101
expect_snapshot_value(comp2, style = "serialize")
101102

@@ -113,6 +114,7 @@ test_that("loo_compare returns expected result (3 models)", {
113114
expect_equal(comp1[1, 1], 0)
114115
expect_s3_class(comp1, "compare.loo")
115116
expect_s3_class(comp1, "matrix")
117+
expect_snapshot(print(comp1))
116118

117119
expect_snapshot_value(comp1, style = "serialize")
118120

tests/testthat/test_kfold_helpers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ test_that("kfold helpers throw correct errors", {
138138

139139
test_that("print_dims.kfold works", {
140140
xx <- structure(list(), K = 17, class = c("kfold", "loo"))
141-
expect_output(print_dims(xx), "Based on 17-fold cross-validation")
141+
expect_snapshot(print_dims(xx))
142142

143143
attr(xx, "K") <- NULL
144144
expect_silent(print_dims(xx))

0 commit comments

Comments
 (0)