Skip to content

Commit b32bb22

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 6aadb5d + 9210e4c commit b32bb22

55 files changed

Lines changed: 1369 additions & 1041 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CONTRIBUTING.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Contributing to bayesplot
2+
3+
This outlines how to propose a change to bayesplot and is based on similar
4+
instructions for tidyverse packages, including the contributing guidelines
5+
generated by `usethis::use_tidy_contributing()`.
6+
7+
## Fixing typos
8+
9+
You can fix typos, spelling mistakes, or grammatical errors in the documentation
10+
directly using the GitHub web interface, as long as the changes are made in the
11+
_source_ file. This generally means you'll need to edit
12+
[roxygen2 comments](https://roxygen2.r-lib.org/articles/roxygen2.html) in an `.R`,
13+
not a `.Rd` file. You can find the `.R` file that generates the `.Rd` by reading
14+
the comment in the first line.
15+
16+
## Bigger changes
17+
18+
If you want to make a bigger change, it's a good idea to first file an issue and
19+
make sure someone from the team agrees that it’s needed. If you’ve found a bug,
20+
please file an issue that illustrates the bug with a minimal reproducible
21+
example (see e.g. the [tidyverse reprex instructions](https://www.tidyverse.org/help/#reprex)).
22+
The tidyverse guide on [how to create a great issue](https://code-review.tidyverse.org/issues/)
23+
has more advice.
24+
25+
### Pull request process
26+
27+
If you are new to creating pull requests here are some tips. Using the functions
28+
from the `usethis` package is not required but can be helpful if this process is
29+
new to you.
30+
31+
* Fork the package and clone onto your computer. If you haven't done this before, we recommend using `usethis::create_from_github("stan-dev/bayesplot", fork = TRUE)`.
32+
33+
* Install all development dependencies with `devtools::install_dev_deps()`, and then make sure the package passes R CMD check by running `devtools::check()`.
34+
If R CMD check doesn't pass cleanly, it's a good idea to ask for help before continuing.
35+
* Create a Git branch for your pull request (PR). We recommend using `usethis::pr_init("brief-description-of-change")`.
36+
37+
* Make your changes, commit to git, and then create a PR by running `usethis::pr_push()`, and following the prompts in your browser.
38+
The title of your PR should briefly describe the change.
39+
The body of your PR should contain `Fixes #issue-number`.
40+
41+
* For user-facing changes, add a bullet to the top of `NEWS.md` (i.e. just below the first header). Follow the style already used in `NEWS.md`.
42+
43+
### Code style
44+
45+
* New code should attempt to follow the style used in the package. When in doubt follow the tidyverse [style guide](https://style.tidyverse.org).
46+
47+
* We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation.
48+
49+
* We use [testthat](https://cran.r-project.org/package=testthat) for unit tests.
50+
Contributions with test cases included are easier to accept.
51+
52+
## Code of Conduct
53+
54+
Please note that the bayesplot project follows the Stan project's
55+
[Code of Conduct](https://discourse.mc-stan.org/t/announcing-our-new-stan-code-of-conduct/23764).
56+
By contributing to this project you agree to abide by its terms.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ tests/testthat/Rplots.pdf
1111
cran-comments.md
1212
revdep/*
1313
CRAN-RELEASE
14+
CRAN-SUBMISSION

DESCRIPTION

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: bayesplot
22
Type: Package
33
Title: Plotting for Bayesian Models
4-
Version: 1.10.0
5-
Date: 2022-11-16
4+
Version: 1.11.0
5+
Date: 2024-01-30
66
Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"), email = "jsg2201@columbia.edu"),
77
person("Tristan", "Mahr", role = "aut"),
88
person("Paul-Christian", "Bürkner", role = "ctb"),
@@ -29,8 +29,8 @@ Depends:
2929
R (>= 3.1.0)
3030
Imports:
3131
dplyr (>= 0.8.0),
32-
ggplot2 (>= 3.0.0),
33-
ggridges,
32+
ggplot2 (>= 3.4.0),
33+
ggridges (>= 0.5.5),
3434
glue,
3535
posterior,
3636
reshape2,
@@ -55,7 +55,7 @@ Suggests:
5555
survival,
5656
testthat (>= 2.0.0),
5757
vdiffr (>= 1.0.2)
58-
RoxygenNote: 7.2.2
58+
RoxygenNote: 7.3.0
5959
VignetteBuilder: knitr
6060
Encoding: UTF-8
6161
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@
22

33
S3method("[",neff_ratio)
44
S3method("[",rhat)
5+
S3method(apply_transformations,array)
6+
S3method(apply_transformations,matrix)
7+
S3method(diagnostic_factor,neff_ratio)
8+
S3method(diagnostic_factor,rhat)
59
S3method(log_posterior,CmdStanMCMC)
610
S3method(log_posterior,stanfit)
711
S3method(log_posterior,stanreg)
12+
S3method(melt_mcmc,matrix)
13+
S3method(melt_mcmc,mcmc_array)
814
S3method(neff_ratio,CmdStanMCMC)
915
S3method(neff_ratio,stanfit)
1016
S3method(neff_ratio,stanreg)
17+
S3method(num_chains,data.frame)
18+
S3method(num_chains,mcmc_array)
19+
S3method(num_iters,data.frame)
20+
S3method(num_iters,mcmc_array)
21+
S3method(num_params,data.frame)
22+
S3method(num_params,mcmc_array)
1123
S3method(nuts_params,CmdStanMCMC)
1224
S3method(nuts_params,list)
1325
S3method(nuts_params,stanfit)
1426
S3method(nuts_params,stanreg)
27+
S3method(parameter_names,array)
28+
S3method(parameter_names,default)
29+
S3method(parameter_names,matrix)
1530
S3method(plot,bayesplot_grid)
1631
S3method(plot,bayesplot_scheme)
1732
S3method(pp_check,default)

NEWS.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<!-- See http://style.tidyverse.org/news.html for advice on writing news -->
22

3+
# bayesplot 1.11.0
4+
5+
* Update for new ggplot2 release by @teunbrand in #309
6+
* Add `bins` argument to many histogram plots by @paul-buerkner in #300
7+
* Follow ggplot2 updates on `facet_grid()` and `facet_wrap()` by @heavywatal in #305
8+
* Better `ppc_loo_pit_qq` plots by @avehtari in #307
9+
* Check `prob` is numeric for intervals plots by @tony-stone in #299
10+
* Add `bins` and `breaks` arguments to more histogram and hex plots by @heavywatal in #313
11+
* Replace `size` argument with `linewidth` for `geom_line` and `geom_ridgeline` by @heavywatal in #314
12+
* All LOO plots now accept `psis_object` argument by @jgabry in #311
13+
* `ppc_pit_ecdf()` and `ppc_pit_ecdf_grouped()` now support discrete variables, and their default method for selecting the number of ECDF evaluation points has been updated. by @TeemuSailynoja in #316
14+
315
# bayesplot 1.10.0
416

517
* New function `mcmc_rank_ecdf()` for rank ecdf plots with confidence bands for
@@ -44,14 +56,14 @@ previous releases, but the new ones in this release are:
4456
- `ppc_error_hist_grouped()`
4557
- `ppc_error_scatter()`
4658
- `ppc_error_binned()`
47-
59+
4860
* New plotting function `ppc_km_overlay_grouped()`, the grouped variant of
4961
`ppc_km_overlay()`. (#260, @fweber144)
5062

5163
* `ppc_scatter()`, `ppc_scatter_avg()`, and `ppc_scatter_avg_grouped()` gain an
5264
argument `ref_line`, which can be set to `FALSE` to turn off the `x=y` line
5365
drawn behind the scatterplot.
54-
66+
5567
* `ppc_ribbon()` and `ppc_ribbon_grouped()` gain argument `y_draw` that specifies whether the observed y should be plotted using a point, line, or both. (#257, @charlesm93)
5668

5769
* `mcmc_*()` functions now support all draws formats from the **posterior** package. (#277, @Ozan147)

R/bayesplot-ggplot-themes.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ theme_default <-
5454
panel.spacing = unit(1.5, "lines"),
5555
legend.position = "right",
5656
legend.background = element_blank(),
57-
legend.text = element_text(size = 13),
58-
legend.text.align = 0,
57+
legend.text = element_text(size = 13, hjust = 0),
5958
legend.key = element_blank()
6059
)
6160
}

R/bayesplot-helpers.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ calc_intervals <- function(x, p, med = TRUE, ...) {
333333
#' equivalent to using `legend_none()`.
334334
#'
335335
legend_move <- function(position = "right") {
336-
theme(legend.position = position)
336+
if (is.numeric(position) && "legend.position.inside" %in% fn_fmls_names(theme)) {
337+
theme(legend.position = "inside", legend.position.inside = position)
338+
} else {
339+
theme(legend.position = position)
340+
}
337341
}
338342
#' @rdname bayesplot-helpers
339343
#' @export

R/helpers-mcmc.R

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ prepare_mcmc_array <- function(x,
5151
if (is.matrix(x)) {
5252
x <- x[, pars, drop=FALSE]
5353
if (length(transformations)) {
54-
x <- apply_transformations(x, transformations)
54+
x <- apply_transformations(x, transformations = transformations)
5555
}
5656
x <- array(x, dim = c(nrow(x), 1, ncol(x)))
5757
} else {
5858
x <- x[, , pars, drop = FALSE]
5959
if (length(transformations)) {
60-
x <- apply_transformations(x, transformations)
60+
x <- apply_transformations(x, transformations = transformations)
6161
}
6262
}
6363

@@ -124,6 +124,8 @@ select_parameters <-
124124
#' @return A molten data frame.
125125
#'
126126
melt_mcmc <- function(x, ...) UseMethod("melt_mcmc")
127+
128+
#' @export
127129
melt_mcmc.mcmc_array <- function(x,
128130
varnames =
129131
c("Iteration", "Chain", "Parameter"),
@@ -144,6 +146,7 @@ melt_mcmc.mcmc_array <- function(x,
144146
}
145147

146148
# If all chains are already merged
149+
#' @export
147150
melt_mcmc.matrix <- function(x,
148151
varnames = c("Draw", "Parameter"),
149152
value.name = "Value",
@@ -305,13 +308,17 @@ chain_list2array <- function(x) {
305308

306309
# Get parameter names from a 3-D array
307310
parameter_names <- function(x) UseMethod("parameter_names")
311+
312+
#' @export
308313
parameter_names.array <- function(x) {
309314
stopifnot(is_3d_array(x))
310315
dimnames(x)[[3]] %||% abort("No parameter names found.")
311316
}
317+
#' @export
312318
parameter_names.default <- function(x) {
313319
colnames(x) %||% abort("No parameter names found.")
314320
}
321+
#' @export
315322
parameter_names.matrix <- function(x) {
316323
colnames(x) %||% abort("No parameter names found.")
317324
}
@@ -388,10 +395,12 @@ validate_transformations <-
388395
#' functions.
389396
#' @return x, with tranformations having been applied to some parameters.
390397
#'
391-
apply_transformations <- function(x, transformations = list(), ...) {
398+
apply_transformations <- function(x, ...) {
392399
UseMethod("apply_transformations")
393400
}
394-
apply_transformations.matrix <- function(x, transformations = list()) {
401+
402+
#' @export
403+
apply_transformations.matrix <- function(x, ..., transformations = list()) {
395404
pars <- colnames(x)
396405
x_transforms <- validate_transformations(transformations, pars)
397406
for (p in names(x_transforms)) {
@@ -400,7 +409,9 @@ apply_transformations.matrix <- function(x, transformations = list()) {
400409

401410
x
402411
}
403-
apply_transformations.array <- function(x, transformations = list()) {
412+
413+
#' @export
414+
apply_transformations.array <- function(x, ..., transformations = list()) {
404415
stopifnot(length(dim(x)) == 3)
405416
pars <- dimnames(x)[[3]]
406417
x_transforms <- validate_transformations(transformations, pars)
@@ -437,17 +448,23 @@ num_chains <- function(x, ...) UseMethod("num_chains")
437448
num_iters <- function(x, ...) UseMethod("num_iters")
438449
num_params <- function(x, ...) UseMethod("num_params")
439450

451+
#' @export
440452
num_params.mcmc_array <- function(x, ...) dim(x)[3]
453+
#' @export
441454
num_chains.mcmc_array <- function(x, ...) dim(x)[2]
455+
#' @export
442456
num_iters.mcmc_array <- function(x, ...) dim(x)[1]
457+
#' @export
443458
num_params.data.frame <- function(x, ...) {
444459
stopifnot("Parameter" %in% colnames(x))
445460
length(unique(x$Parameter))
446461
}
462+
#' @export
447463
num_chains.data.frame <- function(x, ...) {
448464
stopifnot("Chain" %in% colnames(x))
449465
length(unique(x$Chain))
450466
}
467+
#' @export
451468
num_iters.data.frame <- function(x, ...) {
452469
cols <- colnames(x)
453470
stopifnot("Iteration" %in% cols || "Draws" %in% cols)

R/helpers-ppc.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ adjust_gamma_simulate <- function(N, L, K, prob, M) {
416416
#' simultaneous coverage of the ECDF traces.
417417
#' @noRd
418418
interpolate_gamma <- function(N, K, prob, L) {
419-
# Find the precomputed values ueful for the interpolation task.
419+
# Find the precomputed values useful for the interpolation task.
420420
vals <- get_interpolation_values(N, K, L, prob)
421421
# Largest lower bound and smalles upper bound for N among precomputed values.
422422
N_lb <- max(vals[vals$N <= N, ]$N)
423423
N_ub <- min(vals[vals$N >= N, ]$N)
424-
# Approximate largest lower bound and smalles upper bound for gamma.
424+
# Approximate largest lower bound and smallest upper bound for gamma.
425425
log_gamma_lb <- approx(
426426
x = log(vals[vals$N == N_lb, ]$K),
427427
y = log(vals[vals$N == N_lb, ]$val),

R/mcmc-diagnostics-nuts.R

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
#' mcmc_nuts_energy(np)
118118
#' mcmc_nuts_energy(np, merge_chains = TRUE, binwidth = .15)
119119
#' mcmc_nuts_energy(np) +
120-
#' facet_wrap(~ Chain, nrow = 1) +
120+
#' facet_wrap(vars(Chain), nrow = 1) +
121121
#' coord_fixed(ratio = 150) +
122122
#' ggtitle("NUTS Energy Diagnostic")
123123
#' }
@@ -127,15 +127,16 @@ NULL
127127

128128
#' @rdname MCMC-nuts
129129
#' @export
130-
#' @param binwidth An optional value passed to [ggplot2::geom_histogram()] to
131-
#' override the default binwidth.
130+
#' @template args-hist
132131
#'
133132
mcmc_nuts_acceptance <-
134133
function(x,
135134
lp,
136135
chain = NULL,
137136
...,
138-
binwidth = NULL) {
137+
binwidth = NULL,
138+
bins = NULL,
139+
breaks = NULL) {
139140
suggested_package("gridExtra")
140141
check_ignored_arguments(...)
141142

@@ -160,7 +161,9 @@ mcmc_nuts_acceptance <-
160161
color = get_color("lh"),
161162
linewidth = 0.25,
162163
na.rm = TRUE,
163-
binwidth = binwidth
164+
binwidth = binwidth,
165+
bins = bins,
166+
breaks = breaks
164167
) +
165168
bayesplot_theme_get()
166169

@@ -180,7 +183,7 @@ mcmc_nuts_acceptance <-
180183
}
181184
hists <- hists +
182185
dont_expand_y_axis(c(0.005, 0)) +
183-
facet_wrap(~ Parameter, scales = "free") +
186+
facet_wrap(vars(.data$Parameter), scales = "free") +
184187
yaxis_text(FALSE) +
185188
yaxis_title(FALSE) +
186189
yaxis_ticks(FALSE) +
@@ -209,7 +212,9 @@ mcmc_nuts_acceptance <-
209212
color = NA,
210213
alpha = 0.5,
211214
na.rm = TRUE,
212-
binwidth = binwidth
215+
binwidth = binwidth,
216+
bins = bins,
217+
breaks = breaks
213218
)
214219

215220
chain_scatter_data <- data.frame(
@@ -417,6 +422,8 @@ mcmc_nuts_energy <-
417422
function(x,
418423
...,
419424
binwidth = NULL,
425+
bins = NULL,
426+
breaks = NULL,
420427
alpha = 0.5,
421428
merge_chains = FALSE) {
422429
check_ignored_arguments(...)
@@ -446,7 +453,9 @@ mcmc_nuts_energy <-
446453
),
447454
linewidth = 0.25,
448455
na.rm = TRUE,
449-
binwidth = binwidth
456+
binwidth = binwidth,
457+
bins = bins,
458+
breaks = breaks
450459
) +
451460
geom_histogram(
452461
aes(
@@ -457,7 +466,9 @@ mcmc_nuts_energy <-
457466
linewidth = 0.25,
458467
na.rm = TRUE,
459468
alpha = alpha,
460-
binwidth = binwidth
469+
binwidth = binwidth,
470+
bins = bins,
471+
breaks = breaks
461472
) +
462473
scale_fill_manual("", values = fills, labels = aes_labs) +
463474
scale_color_manual("", values = clrs, labels = aes_labs) +
@@ -476,7 +487,7 @@ mcmc_nuts_energy <-
476487
}
477488

478489
graph +
479-
facet_wrap(~ Chain) +
490+
facet_wrap(vars(.data$Chain)) +
480491
force_axes_in_facets()
481492
}
482493

0 commit comments

Comments
 (0)