Skip to content

Commit 44c3e5c

Browse files
authored
Merge pull request #533 from utkarshpawade/fix/ecdf-geom-step-259
Use geom_step() as default in ppc_ecdf_overlay() and deprecate discrete argument
2 parents 7aabd79 + c5a85b7 commit 44c3e5c

11 files changed

+179
-73
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# bayesplot (development version)
22

3+
* `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated.
34
* Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`.
45
* Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`.
56
* Fixed `is_chain_list()` to correctly reject empty lists instead of silently returning `TRUE`.

R/ppc-distributions.R

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@
4141
#' }
4242
#' \item{`ppc_ecdf_overlay()`, `ppc_dens_overlay()`,
4343
#' `ppc_ecdf_overlay_grouped()`, `ppc_dens_overlay_grouped()`}{
44-
#' Kernel density or empirical CDF estimates of each dataset (row) in
45-
#' `yrep` are overlaid, with the distribution of `y` itself on top
46-
#' (and in a darker shade). When using `ppc_ecdf_overlay()` with discrete
47-
#' data, set the `discrete` argument to `TRUE` for better results.
48-
#' For an example of `ppc_dens_overlay()` also see Gabry et al. (2019).
44+
#' Kernel density or empirical CDF estimates of each dataset (row) in `yrep`
45+
#' are overlaid, with the distribution of `y` itself on top (and in a darker
46+
#' shade). For an example of `ppc_dens_overlay()` also see Gabry et al.
47+
#' (2019).
4948
#' }
5049
#' \item{`ppc_violin_grouped()`}{
5150
#' The density estimate of `yrep` within each level of a grouping
@@ -85,7 +84,7 @@
8584
#'
8685
#' ppc_dens_overlay(y, yrep[1:25, ])
8786
#' \donttest{
88-
#' # ppc_ecdf_overlay with continuous data (set discrete=TRUE if discrete data)
87+
#' # ppc_ecdf_overlay
8988
#' ppc_ecdf_overlay(y, yrep[sample(nrow(yrep), 25), ])
9089
#'
9190
#' # PIT-ECDF and PIT-ECDF difference plot of the PIT values of y compared to
@@ -258,20 +257,28 @@ ppc_dens_overlay_grouped <- function(y,
258257

259258
#' @export
260259
#' @rdname PPC-distributions
261-
#' @param discrete For `ppc_ecdf_overlay()`, should the data be treated as
262-
#' discrete? The default is `FALSE`, in which case `geom="line"` is
263-
#' passed to [ggplot2::stat_ecdf()]. If `discrete` is set to
264-
#' `TRUE` then `geom="step"` is used.
260+
#' @param discrete `r lifecycle::badge("deprecated")` The `discrete` argument is
261+
#' deprecated. The ECDF is a step function by definition, so `geom_step()` is
262+
#' now always used.
265263
#' @param pad A logical scalar passed to [ggplot2::stat_ecdf()].
266264
#'
267265
ppc_ecdf_overlay <- function(y,
268266
yrep,
269267
...,
270-
discrete = FALSE,
268+
discrete = deprecated(),
271269
pad = TRUE,
272270
size = 0.25,
273271
alpha = 0.7) {
274272
check_ignored_arguments(...)
273+
274+
if (is_present(discrete)) {
275+
deprecate_warn(
276+
"1.16.0",
277+
"ppc_ecdf_overlay(discrete)",
278+
details = "The ECDF is now always plotted as a step function."
279+
)
280+
}
281+
275282
data <- ppc_data(y, yrep)
276283

277284
ggplot(data) +
@@ -291,15 +298,15 @@ ppc_ecdf_overlay <- function(y,
291298
stat_ecdf(
292299
data = function(x) dplyr::filter(x, !.data$is_y),
293300
mapping = aes(group = .data$rep_id, color = "yrep"),
294-
geom = if (discrete) "step" else "line",
301+
geom = "step",
295302
linewidth = size,
296303
alpha = alpha,
297304
pad = pad
298305
) +
299306
stat_ecdf(
300307
data = function(x) dplyr::filter(x, .data$is_y),
301308
mapping = aes(color = "y"),
302-
geom = if (discrete) "step" else "line",
309+
geom = "step",
303310
linewidth = 1,
304311
pad = pad
305312
) +
@@ -316,17 +323,24 @@ ppc_ecdf_overlay_grouped <- function(y,
316323
yrep,
317324
group,
318325
...,
319-
discrete = FALSE,
326+
discrete = deprecated(),
320327
pad = TRUE,
321328
size = 0.25,
322329
alpha = 0.7) {
323330
check_ignored_arguments(...)
324331

332+
if (is_present(discrete)) {
333+
deprecate_warn(
334+
"1.16.0",
335+
"ppc_ecdf_overlay_grouped(discrete)",
336+
details = "The ECDF is now always plotted as a step function."
337+
)
338+
}
339+
325340
p_overlay <- ppc_ecdf_overlay(
326341
y = y,
327342
yrep = yrep,
328343
...,
329-
discrete = discrete,
330344
pad = pad,
331345
size = size,
332346
alpha = alpha

R/ppd-distributions.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,20 @@ ppd_dens_overlay <-
8383
ppd_ecdf_overlay <-
8484
function(ypred,
8585
...,
86-
discrete = FALSE,
86+
discrete = deprecated(),
8787
pad = TRUE,
8888
size = 0.25,
8989
alpha = 0.7) {
9090
check_ignored_arguments(...)
9191

92+
if (is_present(discrete)) {
93+
deprecate_warn(
94+
"1.16.0",
95+
"ppd_ecdf_overlay(discrete)",
96+
details = "The ECDF is now always plotted as a step function."
97+
)
98+
}
99+
92100
data <- ppd_data(ypred)
93101
ggplot(data, mapping = aes(x = .data$value)) +
94102
hline_at(
@@ -99,7 +107,7 @@ ppd_ecdf_overlay <-
99107
) +
100108
stat_ecdf(
101109
mapping = aes(group = .data$rep_id, color = "ypred"),
102-
geom = if (discrete) "step" else "line",
110+
geom = "step",
103111
linewidth = size,
104112
alpha = alpha,
105113
pad = pad

man/PPC-distributions.Rd

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPD-distributions.Rd

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-default.svg

Lines changed: 11 additions & 11 deletions
Loading

0 commit comments

Comments
 (0)