From 87d78c8f6a79e0aaaef9d5453798e2ce2f12339d Mon Sep 17 00:00:00 2001 From: Tristan Jay Mahr Date: Fri, 2 Feb 2018 15:55:54 -0600 Subject: [PATCH 1/4] start adding more visual tests --- tests/testthat/data-for-ppc-tests.R | 10 ++++++++++ tests/testthat/test-ppc-distributions.R | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tests/testthat/data-for-ppc-tests.R b/tests/testthat/data-for-ppc-tests.R index b1c42e74..4965fd37 100644 --- a/tests/testthat/data-for-ppc-tests.R +++ b/tests/testthat/data-for-ppc-tests.R @@ -5,3 +5,13 @@ group <- gl(4, 25, labels = LETTERS[1:4]) y2 <- rpois(30, 1) yrep2 <- matrix(rpois(30, 1), ncol = 30) group2 <- rep(1, 30) + +set.seed(11172017) +vdiff_y <- rnorm(100) +vdiff_yrep <- matrix(rnorm(2500), ncol = 100) +vdiff_group <- gl(4, 25, labels = LETTERS[1:4]) + +vdiff_y2 <- rpois(30, 1) +vdiff_yrep2 <- matrix(rpois(30, 1), ncol = 30) +vdiff_group2 <- rep(1, 30) +set.seed(seed = NULL) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index 42703ad3..33421a34 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -52,3 +52,18 @@ test_that("ppc_violin_grouped returns a ggplot object", { "'group' must have more than one unique value") }) + +test_that("ppc_violin_grouped renders correctly", { + testthat::skip_on_cran() + + p_base <- ppc_violin_grouped(vdiff_y, vdiff_yrep, vdiff_group) + vdiffr::expect_doppelganger("ppc violin grouped (default)", p_base) + + # lock in jitter + set.seed(100) + p_dots <- ppc_violin_grouped( + vdiff_y, vdiff_yrep, vdiff_group, y_draw = "both") + vdiffr::expect_doppelganger("ppc violin grouped (with points)", p_dots) + + set.seed(seed = NULL) +}) From 9cddc193445be9afbc2867fade4338aa1caf383b Mon Sep 17 00:00:00 2001 From: TJ Mahr Date: Mon, 8 Apr 2019 09:00:59 -0500 Subject: [PATCH 2/4] update vdiffr --- tests/figs/deps.txt | 9 +- .../mcmc-diagnostics/mcmc-neff-default.svg | 196 +-- .../mcmc-neff-hist-binwidth.svg | 246 ++-- .../mcmc-neff-hist-default.svg | 300 ++-- .../mcmc-diagnostics/mcmc-rhat-default.svg | 110 +- .../mcmc-rhat-hist-binwidth.svg | 134 +- .../mcmc-rhat-hist-default.svg | 248 ++-- .../figs/mcmc-diagnostics/mcmc-rhat-sized.svg | 110 +- .../mcmc-intervals/mcmc-areas-default.svg | 112 +- .../mcmc-areas-equal-height.svg | 112 +- .../figs/mcmc-intervals/mcmc-areas-inner.svg | 112 +- .../figs/mcmc-intervals/mcmc-areas-means.svg | 112 +- .../mcmc-intervals/mcmc-areas-no-points.svg | 92 +- .../figs/mcmc-intervals/mcmc-areas-outer.svg | 108 +- .../figs/mcmc-intervals/mcmc-areas-rhats.svg | 154 +- .../mcmc-areas-ridges-default.svg | 122 +- .../mcmc-areas-ridges-inner.svg | 122 +- .../mcmc-areas-ridges-outer.svg | 126 +- .../mcmc-areas-scaled-height.svg | 112 +- .../mcmc-intervals/mcmc-intervals-default.svg | 86 +- .../mcmc-intervals/mcmc-intervals-inner.svg | 86 +- .../mcmc-intervals/mcmc-intervals-means.svg | 86 +- .../mcmc-intervals-no-points.svg | 76 +- .../mcmc-intervals/mcmc-intervals-outer.svg | 78 +- .../mcmc-intervals/mcmc-intervals-rhats.svg | 116 +- .../ppc-boxplot-alpha-size.svg | 148 +- .../ppc-distributions/ppc-boxplot-default.svg | 148 +- .../ppc-boxplot-no-notch.svg | 148 +- .../ppc-distributions/ppc-density-default.svg | 232 +-- .../ppc-density-overlay-alpha-size.svg | 96 +- .../ppc-density-overlay-default.svg | 96 +- .../ppc-ecdf-overlay-alpha-size.svg | 78 +- .../ppc-ecdf-overlay-default.svg | 78 +- .../ppc-freq-poly-grouped-default.svg | 382 ++--- .../ppc-freqpoly-alpha-binwidth-size.svg | 256 ++-- .../ppc-freqpoly-default.svg | 232 +-- .../ppc-distributions/ppc-hist-binwidth.svg | 268 ++-- .../ppc-distributions/ppc-hist-default.svg | 808 +++++------ .../ppc-violin-grouped-default.svg | 100 +- .../ppc-violin-grouped-points-low-jitter.svg | 292 ++-- .../ppc-violin-grouped-with-points.svg | 300 ++-- .../ppc-intervals-default.svg | 1090 +++++++------- .../ppc-intervals-grouped-default.svg | 1288 ++++++++--------- .../ppc-intervals-grouped-x-values.svg | 1272 ++++++++-------- .../ppc-intervals-interval-width.svg | 1090 +++++++------- .../ppc-intervals-x-values.svg | 1094 +++++++------- .../ppc-ribbon-default.svg | 94 +- .../ppc-ribbon-interval-width.svg | 94 +- .../ppc-ribbon-x-values.svg | 98 +- 49 files changed, 6472 insertions(+), 6475 deletions(-) diff --git a/tests/figs/deps.txt b/tests/figs/deps.txt index 8bd22f84..059d3572 100644 --- a/tests/figs/deps.txt +++ b/tests/figs/deps.txt @@ -1,6 +1,3 @@ -Fontconfig: 2.11.94 -FreeType: 2.6.0 -Cairo: 1.14.2 -vdiffr: 0.2.3 -svglite: 1.2.1 -ggplot2: 3.0.0 +- vdiffr-svg-engine: 1.0 +- vdiffr: 0.3.0 +- freetypeharfbuzz: 0.2.5 diff --git a/tests/figs/mcmc-diagnostics/mcmc-neff-default.svg b/tests/figs/mcmc-diagnostics/mcmc-neff-default.svg index 665279ff..f71ba10e 100644 --- a/tests/figs/mcmc-diagnostics/mcmc-neff-default.svg +++ b/tests/figs/mcmc-diagnostics/mcmc-neff-default.svg @@ -2,7 +2,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 + + + + + + + + + + +V2 + + + + + + + + + + + + +0 +100 +200 +300 +400 +500 + + + + + + + +0 +100 +200 +300 +400 +500 + +-4 +-2 +0 +2 +4 + + + + + + +-2 +0 +2 + + + +Chain + + + + +1 +2 +3 +4 +mcmc trace (default) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-divergences-custom.svg b/tests/figs/mcmc-traces/mcmc-trace-divergences-custom.svg new file mode 100644 index 00000000..da78c63f --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-divergences-custom.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 + + + + + + + + + + +0 +100 +200 +300 +400 +500 +V1 +Chain + + + + +1 +2 +3 +4 + +Divergence +mcmc trace divergences (custom) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-divergences-default.svg b/tests/figs/mcmc-traces/mcmc-trace-divergences-default.svg new file mode 100644 index 00000000..b94d56b7 --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-divergences-default.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 + + + + + + + + + + +0 +100 +200 +300 +400 +500 +V1 +Chain + + + + +1 +2 +3 +4 + +Divergence +mcmc trace divergences (default) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-highlight-alpha.svg b/tests/figs/mcmc-traces/mcmc-trace-highlight-alpha.svg new file mode 100644 index 00000000..6a53c1e2 --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-highlight-alpha.svg @@ -0,0 +1,2051 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 + + + + + + + + + + +0 +100 +200 +300 +400 +500 +V1 + + +Other chains +Chain 1 +mcmc trace highlight (alpha) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-highlight-default.svg b/tests/figs/mcmc-traces/mcmc-trace-highlight-default.svg new file mode 100644 index 00000000..f3d53b98 --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-highlight-default.svg @@ -0,0 +1,2051 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 + + + + + + + + + + +0 +100 +200 +300 +400 +500 +V1 + + +Other chains +Chain 1 +mcmc trace highlight (default) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-highlight-other-chain.svg b/tests/figs/mcmc-traces/mcmc-trace-highlight-other-chain.svg new file mode 100644 index 00000000..501102bc --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-highlight-other-chain.svg @@ -0,0 +1,2051 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 + + + + + + + + + + +0 +100 +200 +300 +400 +500 +V1 + + +Other chains +Chain 2 +mcmc trace highlight (other chain) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-iter1-offset.svg b/tests/figs/mcmc-traces/mcmc-trace-iter1-offset.svg new file mode 100644 index 00000000..d59f17a6 --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-iter1-offset.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 + + + + + + + + + + +V2 + + + + + + + + + + + + +200 +300 +400 +500 +600 +700 + + + + + + + +200 +300 +400 +500 +600 +700 + +-4 +-2 +0 +2 +4 + + + + + + +-2 +0 +2 + + + +Chain + + + + +1 +2 +3 +4 +mcmc trace (iter1 offset) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-one-parameter.svg b/tests/figs/mcmc-traces/mcmc-trace-one-parameter.svg new file mode 100644 index 00000000..ed35c284 --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-one-parameter.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 + + + + + + + + + + +0 +100 +200 +300 +400 +500 +V1 +Chain + + + + +1 +2 +3 +4 +mcmc trace (one parameter) + diff --git a/tests/figs/mcmc-traces/mcmc-trace-warmup-window.svg b/tests/figs/mcmc-traces/mcmc-trace-warmup-window.svg new file mode 100644 index 00000000..b64e148c --- /dev/null +++ b/tests/figs/mcmc-traces/mcmc-trace-warmup-window.svg @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 + + + + + + + + + + +V2 + + + + + + + + + + + + +0 +100 +200 +300 +400 +500 + + + + + + + +0 +100 +200 +300 +400 +500 + +-4 +-2 +0 +2 +4 + + + + + + +-2 +0 +2 + + + +Chain + + + + +1 +2 +3 +4 +mcmc trace (warmup window) + diff --git a/tests/testthat/data-for-mcmc-tests.R b/tests/testthat/data-for-mcmc-tests.R index 350656d8..7d68ec95 100644 --- a/tests/testthat/data-for-mcmc-tests.R +++ b/tests/testthat/data-for-mcmc-tests.R @@ -26,4 +26,16 @@ dframe_multiple_chains$chain <- rep(1:4, 25) set.seed(11172017) vdiff_dframe <- as.data.frame(matrix(rnorm(1000), nrow = 100, ncol = 5)) +vdiff_dframe_chains <- as.data.frame( + matrix(rnorm(4000), nrow = 2000, ncol = 2) +) +vdiff_dframe_chains$chain <- rep(1:4, each = 500) + +vdiff_dframe_chains_divergences <- data.frame( + Iteration = rep(1:500, each = 4), + Parameter = "divergent__", + Value = rbinom(2000, size = 1, prob = .02), + Chain = vdiff_dframe_chains$chain, + stringsAsFactors = FALSE +) set.seed(seed = NULL) diff --git a/tests/testthat/test-mcmc-traces.R b/tests/testthat/test-mcmc-traces.R index 4a35acbc..57b2ba5b 100644 --- a/tests/testthat/test-mcmc-traces.R +++ b/tests/testthat/test-mcmc-traces.R @@ -83,3 +83,78 @@ test_that("mcmc_trace 'np' argument works", { expect_message(mcmc_trace(draws, pars = "sigma", np = divs), "No divergences to plot.") }) + + + + +# Visual tests ----------------------------------------------------------------- + +test_that("mcmc_trace renders correctly", { + testthat::skip_on_cran() + + p_base <- mcmc_trace(vdiff_dframe_chains, pars = c("V1", "V2")) + p_one_param <- mcmc_trace(vdiff_dframe_chains, pars = "V1") + + p_warmup <- mcmc_trace( + vdiff_dframe_chains, pars = c("V1", "V2"), + n_warmup = 200 + ) + + p_iter1 <- mcmc_trace( + vdiff_dframe_chains, pars = c("V1", "V2"), iter1 = 200 + ) + + vdiffr::expect_doppelganger("mcmc trace (default)", p_base) + vdiffr::expect_doppelganger("mcmc trace (one parameter)", p_one_param) + vdiffr::expect_doppelganger("mcmc trace (warmup window)", p_warmup) + vdiffr::expect_doppelganger("mcmc trace (iter1 offset)", p_iter1) +}) + +test_that("mcmc_trace_highlight renders correctly", { + testthat::skip_on_cran() + + p_base <- mcmc_trace_highlight( + vdiff_dframe_chains, + pars = "V1", + highlight = 1 + ) + + p_2 <- mcmc_trace_highlight( + vdiff_dframe_chains, + pars = "V1", + highlight = 2 + ) + + p_alpha <- mcmc_trace_highlight( + vdiff_dframe_chains, + pars = "V1", + highlight = 1, + alpha = .1 + ) + + vdiffr::expect_doppelganger("mcmc trace highlight (default)", p_base) + vdiffr::expect_doppelganger("mcmc trace highlight (other chain)", p_2) + vdiffr::expect_doppelganger("mcmc trace highlight (alpha)", p_alpha) +}) + +test_that("mcmc_trace with 'np' renders correctly", { + testthat::skip_on_cran() + + p_base <- mcmc_trace( + vdiff_dframe_chains, + pars = "V1", + np = vdiff_dframe_chains_divergences + ) + + new_style <- trace_style_np(div_color = "black") + + p_np_style <- mcmc_trace( + vdiff_dframe_chains, + pars = "V1", + np = vdiff_dframe_chains_divergences, + np_style = new_style + ) + + vdiffr::expect_doppelganger("mcmc trace divergences (default)", p_base) + vdiffr::expect_doppelganger("mcmc trace divergences (custom)", p_np_style) +}) From 424eda96755ffff538b3f6df7c3f1e9c204b3ca2 Mon Sep 17 00:00:00 2001 From: TJ Mahr Date: Mon, 8 Apr 2019 10:41:49 -0500 Subject: [PATCH 4/4] closes #180. mcmc_recover_scatter() no longer determines x,y range peeking at a prebuilt plot --- R/mcmc-recover.R | 110 ++++++++++++++++------------- tests/testthat/test-mcmc-recover.R | 43 ++++++++--- 2 files changed, 94 insertions(+), 59 deletions(-) diff --git a/R/mcmc-recover.R b/R/mcmc-recover.R index b1c4b92b..fed75c80 100644 --- a/R/mcmc-recover.R +++ b/R/mcmc-recover.R @@ -225,65 +225,73 @@ mcmc_recover_scatter <- size = 3, alpha = 1) { - check_ignored_arguments(...) - x <- merge_chains(prepare_mcmc_array(x)) + check_ignored_arguments(...) + x <- merge_chains(prepare_mcmc_array(x)) - stopifnot( - is.numeric(true), - ncol(x) == length(true), - length(batch) == length(true) - ) - all_separate <- length(unique(batch)) == length(true) - point_est <- match.arg(point_est) - plot_data <- data.frame( - Parameter = colnames(x), - Point = apply(x, 2, point_est), - True = true - ) - if (!all_separate) { - plot_data$Batch <- factor(batch, levels = unique(batch)) - } else { - plot_data$Batch <- - factor(colnames(x), levels = colnames(x)[as.integer(as.factor(batch))]) - } + stopifnot( + is.numeric(true), + ncol(x) == length(true), + length(batch) == length(true) + ) - facet_args[["facets"]] <- ~ Batch - if (is.null(facet_args[["strip.position"]])) - facet_args[["strip.position"]] <- "top" - if (is.null(facet_args[["scales"]])) - facet_args[["scales"]] <- "free" + one_true_per_batch <- length(unique(batch)) == length(true) + one_batch <- length(unique(batch)) == 1 - graph <- ggplot(plot_data, aes_(x = ~ True, y = ~ Point)) + - geom_abline( - slope = 1, - intercept = 0, - linetype = 2, - color = "black" - ) + - geom_point( - shape = 21, - color = get_color("mh"), - fill = get_color("m"), - size = size, - alpha = alpha - ) + - do.call("facet_wrap", facet_args) + - labs(y = "Estimated", x = "True") + - bayesplot_theme_get() + point_est <- match.arg(point_est) + plot_data <- data.frame( + Parameter = colnames(x), + Point = apply(x, 2, point_est), + True = true + ) - if (length(unique(batch)) == 1) { - g <- ggplot_build(graph) - xylim <- g$layout$panel_ranges[[1]] - xylim <- range(xylim$y.range, xylim$x.range) - graph <- graph + coord_fixed(xlim = xylim, ylim = xylim) - } + if (!one_true_per_batch) { + plot_data$Batch <- factor(batch, levels = unique(batch)) + } else { + plot_data$Batch <- + factor(colnames(x), levels = colnames(x)[as.integer(as.factor(batch))]) + } - if (all_separate) - return(graph) + facet_args[["facets"]] <- "Batch" + facet_args[["strip.position"]] <- facet_args[["strip.position"]] %||% "top" + facet_args[["scales"]] <- facet_args[["scales"]] %||% "free" - graph + facet_text(FALSE) + # To ensure that the x and y scales have the same range, find the min and max + # value on each coordinate. plot them invisibly with geom_blank() later on. + corners <- plot_data %>% + group_by(.data$Batch) %>% + summarise( + min = min(pmin(.data$Point, .data$True)), + max = max(pmax(.data$Point, .data$True)) + ) + + graph <- + ggplot(plot_data, aes_(x = ~ True, y = ~ Point)) + + geom_abline( + slope = 1, + intercept = 0, + linetype = 2, + color = "black" + ) + + geom_point( + shape = 21, + color = get_color("mh"), + fill = get_color("m"), + size = size, + alpha = alpha + ) + + geom_blank(aes(x = min, y = min), data = corners) + + geom_blank(aes(x = max, y = max), data = corners) + + do.call("facet_wrap", facet_args) + + labs(x = "True", y = "Estimated") + + bayesplot_theme_get() + + if (one_batch) { + graph <- graph + facet_text(FALSE) } + graph +} + #' @rdname MCMC-recover #' @export diff --git a/tests/testthat/test-mcmc-recover.R b/tests/testthat/test-mcmc-recover.R index 4104bf15..ba691029 100644 --- a/tests/testthat/test-mcmc-recover.R +++ b/tests/testthat/test-mcmc-recover.R @@ -61,14 +61,41 @@ test_that("mcmc_recover_intervals works when point_est = 'none'", { test_that("mcmc_recover_scatter returns a ggplot object", { - expect_gg(mcmc_recover_scatter(draws, true)) - expect_gg(mcmc_recover_scatter(draws, true, batch = 1:4, - point_est = "mean")) - expect_gg(mcmc_recover_scatter(draws, true, batch = c(1, 2, 2, 1), - point_est = "mean")) - expect_gg(mcmc_recover_scatter(draws, true, batch = grepl("X", colnames(draws)))) - expect_gg(mcmc_recover_scatter(draws, true, batch = grepl("X", colnames(draws)), - facet_args = list(ncol = 1))) + expect_gg( + mcmc_recover_scatter(draws, true) + ) + expect_gg( + mcmc_recover_scatter( + draws, + true, + batch = 1:4, + point_est = "mean", + facet_args = list(scales = "fixed") + ) + ) + expect_gg( + mcmc_recover_scatter( + draws, + true, + batch = c(1, 2, 2, 1), + point_est = "mean" + ) + ) + expect_gg( + mcmc_recover_scatter( + draws, + true, + batch = grepl("X", colnames(draws)) + ) + ) + expect_gg( + mcmc_recover_scatter( + draws, + true, + batch = grepl("X", colnames(draws)), + facet_args = list(ncol = 1) + ) + ) })