Skip to content

Commit 529b492

Browse files
committed
add ppd_qdotplot and all tests
1 parent 1407e35 commit 529b492

10 files changed

+7550
-0
lines changed

R/ppd-distributions.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,43 @@ ppd_hist <-
187187
facet_text(FALSE)
188188
}
189189

190+
#' @rdname PPD-distributions
191+
#' @export
192+
ppd_qdotplot <-
193+
function(ypred,
194+
...,
195+
binwidth = NA,
196+
quantiles = NA,
197+
freq = TRUE) {
198+
check_ignored_arguments(...)
199+
200+
suggested_package("ggdist")
201+
202+
data <- ppd_data(ypred)
203+
ggplot(data, mapping = set_hist_aes(
204+
freq,
205+
color = "ypred",
206+
fill = "ypred"
207+
)) +
208+
ggdist::stat_dots(
209+
binwidth = binwidth,
210+
quantiles = quantiles,
211+
overflow = "warn"
212+
) +
213+
scale_color_ppd() +
214+
scale_fill_ppd() +
215+
bayesplot_theme_get() +
216+
facet_wrap_parsed("rep_label") +
217+
force_axes_in_facets() +
218+
dont_expand_y_axis() +
219+
legend_none() +
220+
yaxis_text(FALSE) +
221+
yaxis_title(FALSE) +
222+
yaxis_ticks(FALSE) +
223+
xaxis_title(FALSE) +
224+
facet_text(FALSE)
225+
}
226+
190227

191228
#' @rdname PPD-distributions
192229
#' @export

tests/testthat/_snaps/ppc-distributions/ppc-qdotplot-binwidth.svg

Lines changed: 950 additions & 0 deletions
Loading

tests/testthat/_snaps/ppc-distributions/ppc-qdotplot-default.svg

Lines changed: 1265 additions & 0 deletions
Loading

tests/testthat/_snaps/ppc-distributions/ppc-qdotplot-quantile-binwidth.svg

Lines changed: 867 additions & 0 deletions
Loading

tests/testthat/_snaps/ppc-distributions/ppc-qdotplot-quantile.svg

Lines changed: 869 additions & 0 deletions
Loading

tests/testthat/_snaps/ppc-distributions/ppd-qdotplot-binwidth.svg

Lines changed: 809 additions & 0 deletions
Loading

tests/testthat/_snaps/ppc-distributions/ppd-qdotplot-default.svg

Lines changed: 1138 additions & 0 deletions
Loading

tests/testthat/_snaps/ppc-distributions/ppd-qdotplot-quantile-binwidth.svg

Lines changed: 780 additions & 0 deletions
Loading

tests/testthat/_snaps/ppc-distributions/ppd-qdotplot-quantile.svg

Lines changed: 787 additions & 0 deletions
Loading

tests/testthat/test-ppc-distributions.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ test_that("ppc_dens,pp_hist,ppc_freqpoly,ppc_boxplot return ggplot objects", {
5858
expect_gg(ppd_boxplot(yrep2, notch = FALSE))
5959
})
6060

61+
test_that("ppc_qdotplot returns a ggplot object", {
62+
testthat::skip_if_not_installed("ggdist")
63+
64+
expect_gg(ppc_qdotplot(y, yrep[1:8, ]))
65+
expect_gg(ppc_qdotplot(y, yrep[1,, drop = FALSE], quantiles=25))
66+
expect_gg(ppc_qdotplot(y, yrep[1:8, ], binwidth = 0.1))
67+
expect_gg(ppc_qdotplot(y2, yrep2, binwidth = 0.1, quantiles = 25))
68+
69+
70+
# ppd versions
71+
expect_gg(ppd_qdotplot(y, yrep[1:8, ]))
72+
expect_gg(ppd_qdotplot(yrep[1,, drop = FALSE], quantiles = 25))
73+
expect_gg(ppd_qdotplot(yrep[1:8, ], binwidth = 0.1))
74+
expect_gg(ppd_qdotplot(yrep2, binwidth = 0.1, quantiles = 25))
75+
})
76+
6177
test_that("ppc_pit_ecdf, ppc_pit_ecdf_grouped returns a ggplot object", {
6278
expect_gg(ppc_pit_ecdf(y, yrep, interpolate_adj = FALSE))
6379
expect_gg(ppc_pit_ecdf_grouped(y, yrep, group = group, interpolate_adj = FALSE))
@@ -177,6 +193,38 @@ test_that("ppc_boxplot renders correctly", {
177193
vdiffr::expect_doppelganger("ppd_boxplot (alpha, size)", p_custom)
178194
})
179195

196+
test_that("ppc_qdotplot renders correctly", {
197+
testthat::skip_on_cran()
198+
testthat::skip_if_not_installed("vdiffr")
199+
testthat::skip_if_not_installed("ggdist")
200+
skip_on_r_oldrel()
201+
202+
p_base <- ppc_qdotplot(vdiff_y, vdiff_yrep[1:8, ])
203+
vdiffr::expect_doppelganger("ppc_qdotplot (default)", p_base)
204+
205+
p_binwidth <- ppc_qdotplot(vdiff_y, vdiff_yrep[1:8, ], binwidth = 3)
206+
vdiffr::expect_doppelganger("ppc_qdotplot (binwidth)", p_binwidth)
207+
208+
p_quantile <- ppc_qdotplot(vdiff_y, vdiff_yrep[1:8, ], quantiles = 50)
209+
vdiffr::expect_doppelganger("ppc_qdotplot (quantile)", p_quantile)
210+
211+
p_quantile_binwidth <- ppc_qdotplot(vdiff_y, vdiff_yrep[1:8, ], binwidth = 3, quantiles = 50)
212+
vdiffr::expect_doppelganger("ppc_qdotplot (quantile-binwidth)", p_quantile_binwidth)
213+
214+
# ppd versions
215+
p_base <- ppd_qdotplot(vdiff_yrep[1:8, ])
216+
vdiffr::expect_doppelganger("ppd_qdotplot (default)", p_base)
217+
218+
p_binwidth <- ppd_qdotplot(vdiff_yrep[1:8, ], binwidth = 3)
219+
vdiffr::expect_doppelganger("ppd_qdotplot (binwidth)", p_binwidth)
220+
221+
p_quantile <- ppd_qdotplot(vdiff_yrep[1:8, ], quantiles = 50)
222+
vdiffr::expect_doppelganger("ppd_qdotplot (quantile)", p_quantile)
223+
224+
p_quantile_binwidth <- ppd_qdotplot(vdiff_yrep[1:8, ], binwidth = 3, quantiles = 50)
225+
vdiffr::expect_doppelganger("ppd_qdotplot (quantile-binwidth)", p_quantile_binwidth)
226+
})
227+
180228
test_that("ppc_ecdf_overlay renders correctly", {
181229
testthat::skip_on_cran()
182230
testthat::skip_if_not_installed("vdiffr")

0 commit comments

Comments
 (0)