1
1
library(bayesplot )
2
2
suppressPackageStartupMessages(library(rstanarm ))
3
- context(" MCMC: scatter and parallel coordinates plots" )
3
+ context(" MCMC: scatter, hex, and parallel coordinates plots" )
4
4
5
5
source(test_path(" data-for-mcmc-tests.R" ))
6
6
@@ -15,6 +15,8 @@ divs <- sample(c(0,1), size = 1000, prob = c(0.25, 0.75), replace = TRUE)
15
15
np $ Value [np $ Parameter == " divergent__" ] <- divs # fake divergences
16
16
17
17
18
+
19
+ # mcmc_scatter/hex --------------------------------------------------------
18
20
test_that(" mcmc_scatter returns a ggplot object" , {
19
21
expect_gg(mcmc_scatter(arr , pars = c(" beta[1]" , " beta[2]" )))
20
22
expect_gg(mcmc_scatter(arr1chain , regex_pars = " beta" , size = 3 , alpha = 0.5 ))
@@ -24,13 +26,8 @@ test_that("mcmc_scatter returns a ggplot object", {
24
26
pars = c(" sigma" , " (Intercept)" )))
25
27
})
26
28
27
- test_that(" mcmc_hex returns a ggplot object" , {
28
- skip_if_not_installed(" hexbin" )
29
- expect_gg(mcmc_hex(arr , pars = c(" beta[1]" , " beta[2]" )))
30
- expect_gg(mcmc_hex(arr1chain , regex_pars = " beta" , binwidth = c(.5 ,.5 )))
31
- })
32
-
33
- test_that(" mcmc_scatter throws error if only 1 parameter" , {
29
+ test_that(" mcmc_scatter throws error if number of parameters is not 2" , {
30
+ expect_error(mcmc_scatter(arr , pars = c(" sigma" , " beta[1]" , " beta[2]" )), " exactly 2 parameters" )
34
31
expect_error(mcmc_scatter(arr , pars = " sigma" ), " exactly 2 parameters" )
35
32
expect_error(mcmc_scatter(arr1 ), " exactly 2 parameters" )
36
33
expect_error(mcmc_scatter(mat1 ), " exactly 2 parameters" )
@@ -46,6 +43,21 @@ test_that("mcmc_scatter accepts NUTS info", {
46
43
expect_named(g $ data , c(" x" , " y" , " Divergent" ))
47
44
})
48
45
46
+ test_that(" mcmc_hex returns a ggplot object" , {
47
+ skip_if_not_installed(" hexbin" )
48
+ expect_gg(mcmc_hex(arr , pars = c(" beta[1]" , " beta[2]" )))
49
+ expect_gg(mcmc_hex(arr1chain , regex_pars = " beta" , binwidth = c(.5 ,.5 )))
50
+ })
51
+
52
+ test_that(" mcmc_hex throws error if number of parameters is not 2" , {
53
+ skip_if_not_installed(" hexbin" )
54
+ expect_error(mcmc_hex(arr , pars = c(" sigma" , " beta[1]" , " beta[2]" )), " exactly 2 parameters" )
55
+ expect_error(mcmc_hex(arr , pars = " sigma" ), " exactly 2 parameters" )
56
+ expect_error(mcmc_hex(arr1 ), " exactly 2 parameters" )
57
+ expect_error(mcmc_hex(mat1 ), " exactly 2 parameters" )
58
+ })
59
+
60
+
49
61
50
62
# mcmc_pairs -------------------------------------------------------------
51
63
test_that(" mcmc_pairs returns a bayesplot_grid object" , {
0 commit comments