Skip to content

Commit 58e3618

Browse files
committed
Add test for #176
1 parent 1a9a1ef commit 58e3618

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/testthat/test-mcmc-diagnostics.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,31 @@ test_that("duplicated rhats and neffs are kept (#105)", {
5353
expect_equal(nrow(df), length(ratios))
5454
})
5555

56+
test_that("'description' & 'rating' columns are correct (#176)", {
57+
# https://github.com/stan-dev/bayesplot/issues/176
58+
rhats <- c(1, 1.07, 1.19, 1.07, 1.3, 1)
59+
expected_rhats <- sort(rhats)
60+
expected_ratings <- rep(c("low", "ok", "high"), each = 2)
61+
expected_descriptions <-
62+
rep(c("hat(R) <= 1.05", "hat(R) <= 1.1", "hat(R) > 1.1"), each = 2)
63+
64+
df <- mcmc_rhat_data(rhats)
65+
expect_equal(df$value, expected_rhats)
66+
expect_equal(as.character(df$rating), expected_ratings)
67+
expect_equal(df$description, expected_descriptions)
68+
69+
ratios <- c(0.4, 0.05, 0.6)
70+
expected_ratios <- sort(ratios)
71+
expected_ratings <- c("low", "ok", "high")
72+
expected_descriptions <-
73+
c("N[eff]/N <= 0.1", "N[eff]/N <= 0.5", "N[eff]/N > 0.5")
74+
75+
df <- mcmc_neff_data(ratios)
76+
expect_equal(df$value, expected_ratios)
77+
expect_equal(as.character(df$rating), expected_ratings)
78+
expect_equal(df$description, expected_descriptions)
79+
})
80+
5681
test_that("mcmc_acf & mcmc_acf_bar return a ggplot object", {
5782
expect_gg(mcmc_acf(arr, pars = "beta[1]", regex_pars = "x\\:[2,5]"))
5883
expect_gg(mcmc_acf_bar(arr, pars = "beta[1]", regex_pars = "x\\:[2,5]"))

0 commit comments

Comments
 (0)