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
@@ -10,6 +10,8 @@ post <- as.array(fit)
10
10
lp <- log_posterior(fit )
11
11
np <- ensure_divergences(nuts_params(fit ))
12
12
13
+
14
+ # mcmc_scatter/hex --------------------------------------------------------
13
15
test_that(" mcmc_scatter returns a ggplot object" , {
14
16
expect_gg(mcmc_scatter(arr , pars = c(" beta[1]" , " beta[2]" )))
15
17
expect_gg(mcmc_scatter(arr1chain , regex_pars = " beta" , size = 3 , alpha = 0.5 ))
@@ -19,17 +21,11 @@ test_that("mcmc_scatter returns a ggplot object", {
19
21
pars = c(" sigma" , " (Intercept)" )))
20
22
})
21
23
22
- test_that(" mcmc_hex returns a ggplot object" , {
23
- expect_gg(mcmc_hex(arr , pars = c(" beta[1]" , " beta[2]" )))
24
- expect_gg(mcmc_hex(arr1chain , regex_pars = " beta" , binwidth = c(.5 ,.5 )))
25
- })
26
-
27
- test_that(" mcmc_scatter & mcmc_hex throw error if only 1 parameter" , {
24
+ test_that(" mcmc_scatter throws error if number of parameters is not 2" , {
25
+ expect_error(mcmc_scatter(arr , pars = c(" sigma" , " beta[1]" , " beta[2]" )), " exactly 2 parameters" )
28
26
expect_error(mcmc_scatter(arr , pars = " sigma" ), " exactly 2 parameters" )
29
27
expect_error(mcmc_scatter(arr1 ), " exactly 2 parameters" )
30
28
expect_error(mcmc_scatter(mat1 ), " exactly 2 parameters" )
31
- expect_error(mcmc_hex(dframe1 ), " exactly 2 parameters" )
32
- expect_error(mcmc_hex(chainlist1 ), " exactly 2 parameters" )
33
29
})
34
30
35
31
test_that(" mcmc_scatter accepts NUTS info" , {
@@ -42,6 +38,21 @@ test_that("mcmc_scatter accepts NUTS info", {
42
38
expect_named(g $ data , c(" x" , " y" , " Divergent" ))
43
39
})
44
40
41
+ test_that(" mcmc_hex returns a ggplot object" , {
42
+ skip_if_not_installed(" hexbin" )
43
+ expect_gg(mcmc_hex(arr , pars = c(" beta[1]" , " beta[2]" )))
44
+ expect_gg(mcmc_hex(arr1chain , regex_pars = " beta" , binwidth = c(.5 ,.5 )))
45
+ })
46
+
47
+ test_that(" mcmc_hex throws error if number of parameters is not 2" , {
48
+ skip_if_not_installed(" hexbin" )
49
+ expect_error(mcmc_hex(arr , pars = c(" sigma" , " beta[1]" , " beta[2]" )), " exactly 2 parameters" )
50
+ expect_error(mcmc_hex(arr , pars = " sigma" ), " exactly 2 parameters" )
51
+ expect_error(mcmc_hex(arr1 ), " exactly 2 parameters" )
52
+ expect_error(mcmc_hex(mat1 ), " exactly 2 parameters" )
53
+ })
54
+
55
+
45
56
46
57
# mcmc_pairs -------------------------------------------------------------
47
58
test_that(" mcmc_pairs returns a bayesplot_grid object" , {
0 commit comments