Skip to content

Commit 2e336a5

Browse files
Merge branch 'master' into test/data-functions-edge-cases
2 parents cd0dfee + 44c3e5c commit 2e336a5

19 files changed

Lines changed: 209 additions & 83 deletions

.github/workflows/R-CMD-check.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ jobs:
4141
r-version: ${{ matrix.config.r }}
4242
http-user-agent: ${{ matrix.config.http-user-agent }}
4343
use-public-rspm: true
44+
extra-repositories: |
45+
https://community.r-multiverse.org
46+
https://stan-dev.r-universe.dev
4447
4548
- uses: r-lib/actions/setup-r-dependencies@v2
4649
with:
47-
extra-packages: any::rcmdcheck, any::BH, any::RcppEigen, any::vdiffr
50+
extra-packages: any::rcmdcheck, any::BH, any::RcppEigen, any::vdiffr, any::cmdstanr
4851
needs: check
4952

53+
- name: Install CmdStan
54+
run: Rscript -e "cmdstanr::install_cmdstan()"
55+
5056
- uses: r-lib/actions/check-r-package@v2
5157
with:
5258
upload-snapshots: true

.github/workflows/pkgdown.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- uses: r-lib/actions/setup-r@v2
3131
with:
3232
use-public-rspm: true
33+
extra-repositories: |
34+
https://community.r-multiverse.org
35+
https://stan-dev.r-universe.dev
3336
3437
- uses: r-lib/actions/setup-r-dependencies@v2
3538
with:

.github/workflows/test-coverage.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ jobs:
2323
- uses: r-lib/actions/setup-r@v2
2424
with:
2525
use-public-rspm: true
26+
extra-repositories: 'https://stan-dev.r-universe.dev'
2627

2728
- uses: r-lib/actions/setup-r-dependencies@v2
2829
with:
29-
extra-packages: any::covr, any::xml2, any::vdiffr
30+
extra-packages: any::covr, any::xml2, any::vdiffr, any::cmdstanr
3031
needs: coverage
3132

33+
- name: Install CmdStan
34+
run: Rscript -e "cmdstanr::install_cmdstan()"
35+
3236
- name: Test coverage
3337
run: |
3438
cov <- covr::package_coverage(

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Imports:
4444
tidyselect,
4545
utils
4646
Suggests:
47+
cmdstanr,
4748
ggdist,
4849
ggfortify,
4950
gridExtra (>= 2.2.1),
@@ -65,3 +66,4 @@ VignetteBuilder: knitr
6566
Encoding: UTF-8
6667
Roxygen: list(markdown = TRUE)
6768
Config/testthat/edition: 3
69+
Additional_repositories: https://stan-dev.r-universe.dev/

NEWS.md

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

33
* Added singleton-dimension edge-case tests for exported `_data()` functions.
4+
* `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated.
5+
* Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`.
6+
* Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`.
47
* Fixed `is_chain_list()` to correctly reject empty lists instead of silently returning `TRUE`.
58
* Added unit tests for `mcmc_areas_ridges_data()`, `mcmc_parcoord_data()`, and `mcmc_trace_data()`.
69
* Added unit tests for `ppc_error_data()` and `ppc_loo_pit_data()` covering output structure, argument handling, and edge cases.

R/bayesplot-extractors.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ nuts_params.list <- function(object, pars = NULL, ...) {
175175
nuts_params.CmdStanMCMC <- function(object, pars = NULL, ...) {
176176
arr <- object$sampler_diagnostics()
177177
if (!is.null(pars)) {
178-
arr <- arr[,, pars]
178+
arr <- arr[,, pars, drop = FALSE]
179179
}
180180
out <- reshape2::melt(arr)
181181
colnames(out)[colnames(out) == "variable"] <- "parameter"

R/helpers-ppc.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ validate_predictions <- function(predictions, n_obs = NULL) {
7373
}
7474

7575
if (is.integer(predictions)) {
76-
if (nrow(predictions) == 1) {
77-
predictions[1, ] <- as.numeric(predictions[1,, drop = FALSE])
78-
}
79-
else {
80-
predictions <- apply(predictions, 2, as.numeric)
81-
}
76+
storage.mode(predictions) <- "numeric"
8277
}
8378

8479
if (anyNA(predictions)) {

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.

0 commit comments

Comments
 (0)