Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# bayesplot (development version)

* `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated.
* Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`.
* Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`.
* Fixed `is_chain_list()` to correctly reject empty lists instead of silently returning `TRUE`.
Expand Down
44 changes: 29 additions & 15 deletions R/ppc-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@
#' }
#' \item{`ppc_ecdf_overlay()`, `ppc_dens_overlay()`,
#' `ppc_ecdf_overlay_grouped()`, `ppc_dens_overlay_grouped()`}{
#' Kernel density or empirical CDF estimates of each dataset (row) in
#' `yrep` are overlaid, with the distribution of `y` itself on top
#' (and in a darker shade). When using `ppc_ecdf_overlay()` with discrete
#' data, set the `discrete` argument to `TRUE` for better results.
#' For an example of `ppc_dens_overlay()` also see Gabry et al. (2019).
#' Kernel density or empirical CDF estimates of each dataset (row) in `yrep`
#' are overlaid, with the distribution of `y` itself on top (and in a darker
#' shade). For an example of `ppc_dens_overlay()` also see Gabry et al.
#' (2019).
#' }
#' \item{`ppc_violin_grouped()`}{
#' The density estimate of `yrep` within each level of a grouping
Expand Down Expand Up @@ -85,7 +84,7 @@
#'
#' ppc_dens_overlay(y, yrep[1:25, ])
#' \donttest{
#' # ppc_ecdf_overlay with continuous data (set discrete=TRUE if discrete data)
#' # ppc_ecdf_overlay
#' ppc_ecdf_overlay(y, yrep[sample(nrow(yrep), 25), ])
#'
#' # PIT-ECDF and PIT-ECDF difference plot of the PIT values of y compared to
Expand Down Expand Up @@ -258,20 +257,28 @@ ppc_dens_overlay_grouped <- function(y,

#' @export
#' @rdname PPC-distributions
#' @param discrete For `ppc_ecdf_overlay()`, should the data be treated as
#' discrete? The default is `FALSE`, in which case `geom="line"` is
#' passed to [ggplot2::stat_ecdf()]. If `discrete` is set to
#' `TRUE` then `geom="step"` is used.
#' @param discrete `r lifecycle::badge("deprecated")` The `discrete` argument is
#' deprecated. The ECDF is a step function by definition, so `geom_step()` is
#' now always used.
#' @param pad A logical scalar passed to [ggplot2::stat_ecdf()].
#'
ppc_ecdf_overlay <- function(y,
yrep,
...,
discrete = FALSE,
discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7) {
check_ignored_arguments(...)

if (is_present(discrete)) {
deprecate_warn(
"1.16.0",
"ppc_ecdf_overlay(discrete)",
details = "The ECDF is now always plotted as a step function."
)
}

data <- ppc_data(y, yrep)

ggplot(data) +
Expand All @@ -291,15 +298,15 @@ ppc_ecdf_overlay <- function(y,
stat_ecdf(
data = function(x) dplyr::filter(x, !.data$is_y),
mapping = aes(group = .data$rep_id, color = "yrep"),
geom = if (discrete) "step" else "line",
geom = "step",
linewidth = size,
alpha = alpha,
pad = pad
) +
stat_ecdf(
data = function(x) dplyr::filter(x, .data$is_y),
mapping = aes(color = "y"),
geom = if (discrete) "step" else "line",
geom = "step",
linewidth = 1,
pad = pad
) +
Expand All @@ -316,17 +323,24 @@ ppc_ecdf_overlay_grouped <- function(y,
yrep,
group,
...,
discrete = FALSE,
discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7) {
check_ignored_arguments(...)

if (is_present(discrete)) {
deprecate_warn(
"1.16.0",
"ppc_ecdf_overlay_grouped(discrete)",
details = "The ECDF is now always plotted as a step function."
)
}

p_overlay <- ppc_ecdf_overlay(
y = y,
yrep = yrep,
...,
discrete = discrete,
pad = pad,
size = size,
alpha = alpha
Expand Down
12 changes: 10 additions & 2 deletions R/ppd-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,20 @@ ppd_dens_overlay <-
ppd_ecdf_overlay <-
function(ypred,
...,
discrete = FALSE,
discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7) {
check_ignored_arguments(...)

if (is_present(discrete)) {
deprecate_warn(
"1.16.0",
"ppd_ecdf_overlay(discrete)",
details = "The ECDF is now always plotted as a step function."
)
}

data <- ppd_data(ypred)
ggplot(data, mapping = aes(x = .data$value)) +
hline_at(
Expand All @@ -99,7 +107,7 @@ ppd_ecdf_overlay <-
) +
stat_ecdf(
mapping = aes(group = .data$rep_id, color = "ypred"),
geom = if (discrete) "step" else "line",
geom = "step",
linewidth = size,
alpha = alpha,
pad = pad
Expand Down
22 changes: 10 additions & 12 deletions man/PPC-distributions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions man/PPD-distributions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading