Skip to content

Commit a807d2c

Browse files
authored
Merge pull request #222 from stan-dev/ppd-functions
Add new PPD module for plots without `y` variable
2 parents 42f7b51 + e16ef30 commit a807d2c

File tree

140 files changed

+16310
-6243
lines changed

Some content is hidden

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

140 files changed

+16310
-6243
lines changed

.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ images/*
1313
book/*
1414
docs/*
1515
Rplots.pdf
16-
tests/figs/*
1716
^\.github$
17+
^tests/testthat/_snaps$

DESCRIPTION

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"), email = "jsg2201@c
77
person("Tristan", "Mahr", role = "aut"),
88
person("Paul-Christian", "Bürkner", role = "ctb"),
99
person("Martin", "Modrák", role = "ctb"),
10-
person("Malcolm", "Barrett", role = "ctb"),
10+
person("Malcolm", "Barrett", role = "ctb"),
1111
person("Frank", "Weber", role = "ctb"),
1212
person("Eduardo", "Coronado Sroka", role = "ctb"),
1313
person("Aki", "Vehtari", role = "ctb"))
1414
Maintainer: Jonah Gabry <jsg2201@columbia.edu>
1515
Description: Plotting functions for posterior analysis, MCMC diagnostics,
16-
prior and posterior predictive checks, and other visualizations
16+
prior and posterior predictive checks, and other visualizations
1717
to support the applied Bayesian workflow advocated in
1818
Gabry, Simpson, Vehtari, Betancourt, and Gelman (2019) <doi:10.1111/rssa.12378>.
19-
The package is designed not only to provide convenient functionality
20-
for users, but also a common set of functions that can be easily used by
21-
developers working on a variety of R packages for Bayesian modeling,
19+
The package is designed not only to provide convenient functionality
20+
for users, but also a common set of functions that can be easily used by
21+
developers working on a variety of R packages for Bayesian modeling,
2222
particularly (but not exclusively) packages interfacing with 'Stan'.
2323
License: GPL (>= 3)
2424
URL: https://mc-stan.org/bayesplot/
@@ -35,10 +35,10 @@ Imports:
3535
reshape2,
3636
rlang (>= 0.3.0),
3737
stats,
38-
tibble,
38+
tibble (>= 2.0.0),
3939
tidyselect,
4040
utils
41-
Suggests:
41+
Suggests:
4242
ggfortify,
4343
gridExtra (>= 2.2.1),
4444
hexbin,
@@ -53,7 +53,7 @@ Suggests:
5353
shinystan (>= 2.3.0),
5454
survival,
5555
testthat (>= 2.0.0),
56-
vdiffr
56+
vdiffr (>= 1.0.2)
5757
RoxygenNote: 7.1.2
5858
VignetteBuilder: knitr
5959
Encoding: UTF-8

NAMESPACE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ S3method(rhat,stanreg)
2424
export(abline_01)
2525
export(available_mcmc)
2626
export(available_ppc)
27+
export(available_ppd)
2728
export(bayesplot_grid)
2829
export(bayesplot_theme_get)
2930
export(bayesplot_theme_replace)
@@ -99,6 +100,7 @@ export(parcoord_style_np)
99100
export(plot_bg)
100101
export(pp_check)
101102
export(ppc_bars)
103+
export(ppc_bars_data)
102104
export(ppc_bars_grouped)
103105
export(ppc_boxplot)
104106
export(ppc_data)
@@ -108,10 +110,12 @@ export(ppc_dens_overlay_grouped)
108110
export(ppc_ecdf_overlay)
109111
export(ppc_ecdf_overlay_grouped)
110112
export(ppc_error_binned)
113+
export(ppc_error_data)
111114
export(ppc_error_hist)
112115
export(ppc_error_hist_grouped)
113116
export(ppc_error_scatter)
114117
export(ppc_error_scatter_avg)
118+
export(ppc_error_scatter_avg_grouped)
115119
export(ppc_error_scatter_avg_vs_x)
116120
export(ppc_freqpoly)
117121
export(ppc_freqpoly_grouped)
@@ -133,12 +137,36 @@ export(ppc_ribbon_grouped)
133137
export(ppc_rootogram)
134138
export(ppc_scatter)
135139
export(ppc_scatter_avg)
140+
export(ppc_scatter_avg_data)
136141
export(ppc_scatter_avg_grouped)
142+
export(ppc_scatter_data)
137143
export(ppc_stat)
138144
export(ppc_stat_2d)
145+
export(ppc_stat_data)
146+
export(ppc_stat_freqpoly)
139147
export(ppc_stat_freqpoly_grouped)
140148
export(ppc_stat_grouped)
141149
export(ppc_violin_grouped)
150+
export(ppd_boxplot)
151+
export(ppd_data)
152+
export(ppd_dens)
153+
export(ppd_dens_overlay)
154+
export(ppd_ecdf_overlay)
155+
export(ppd_freqpoly)
156+
export(ppd_freqpoly_grouped)
157+
export(ppd_hist)
158+
export(ppd_intervals)
159+
export(ppd_intervals_data)
160+
export(ppd_intervals_grouped)
161+
export(ppd_ribbon)
162+
export(ppd_ribbon_data)
163+
export(ppd_ribbon_grouped)
164+
export(ppd_stat)
165+
export(ppd_stat_2d)
166+
export(ppd_stat_data)
167+
export(ppd_stat_freqpoly)
168+
export(ppd_stat_freqpoly_grouped)
169+
export(ppd_stat_grouped)
142170
export(rhat)
143171
export(scatter_style_np)
144172
export(theme_default)
@@ -156,8 +184,10 @@ import(ggplot2)
156184
import(rlang)
157185
import(stats)
158186
importFrom(dplyr,"%>%")
187+
importFrom(dplyr,across)
159188
importFrom(dplyr,arrange)
160189
importFrom(dplyr,count)
190+
importFrom(dplyr,full_join)
161191
importFrom(dplyr,group_by)
162192
importFrom(dplyr,inner_join)
163193
importFrom(dplyr,left_join)

NEWS.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
# bayesplot 1.8.1.9000
44

5+
* New module PPD (posterior/prior predictive distribution) with a lot of new
6+
plotting functions with `ppd_` prefix. These functions plot draws from the prior
7+
or posterior predictive distributions (PPD) without comparing to observed data
8+
(i.e., no `y` argument). Because these are not "checks" against the observed
9+
data we use PPD instead of PPC. These plots are essentially the same as the
10+
corresponding PPC plots but without showing any observed data (e.g.,
11+
`ppd_intervals()` is like `ppc_intervals()` but without plotting `y`). See
12+
`help("PPD-overview")` for details. (#151, #222)
13+
14+
* All PPC categories now have one or more `_data()` functions that return the
15+
data frame used for plotting (#97, #222). Many of these have already been in
16+
previous releases, but the new ones in this release are:
17+
- `ppc_bars_data()`
18+
- `ppc_error_data()`
19+
- `ppc_error_binnned_data()`
20+
- `ppc_scatter_data()`
21+
- `ppc_scatter_avg_data()`
22+
- `ppc_stat_data()`
23+
24+
* Many functions gain an argument `facet_args` for controlling ggplot2 faceting
25+
(many other functions have had this argument for a long time).
26+
The ones that just now got the argument are:
27+
- `ppc_scatter()`
28+
- `ppc_scatter_avg_grouped()`
29+
- `ppc_error_hist()`
30+
- `ppc_error_hist_grouped()`
31+
- `ppc_error_scatter()`
32+
- `ppc_error_binned()`
33+
34+
* New plotting function `ppc_km_overlay_grouped()`, the grouped variant of
35+
`ppc_km_overlay()`. (#260, @fweber144)
36+
37+
* `ppc_scatter()`, `ppc_scatter_avg()`, and `ppc_scatter_avg_grouped()` gain an
38+
argument `ref_line`, which can be set to `FALSE` to turn off the `x=y` line
39+
drawn behind the scatterplot.
40+
541
* `mcmc_*()` functions now support all draws formats from the **posterior** package. (#277, @Ozan147)
642

743
* `mcmc_dens()` and `mcmc_dens_overlay()` gain arguments for controlling the
@@ -12,9 +48,6 @@
1248
* `mcmc_areas()` and `mcmc_areas_ridges()` gain an argument `border_size` for
1349
controlling the thickness of the ridgelines. (#224)
1450

15-
* New plotting function `ppc_km_overlay_grouped()`, the grouped variant of
16-
`ppc_km_overlay()`. (#260, @fweber144)
17-
1851
# bayesplot 1.8.1
1952

2053
* Fix R cmd check error on linux for CRAN

R/available-module-functions.R

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,82 @@
1-
#' Get or view the names of available plotting functions
1+
#' Get or view the names of available plotting or data functions
22
#'
33
#' @export
44
#' @param pattern,fixed,invert Passed to [base::grep()].
5+
#' @param plots_only If `TRUE` (the default) only plotting functions are
6+
#' searched for. If `FALSE` then functions that return data for plotting
7+
#' (functions ending in `_data()`) are also included.
58
#' @return A possibly empty character vector of function names with several
69
#' additional attributes (for use by a custom print method). If `pattern`
710
#' is missing then the returned object contains the names of all available
8-
#' plotting functions in the [MCMC] or [PPC] module, depending on
11+
#' plotting functions in the [MCMC], [PPC], or [PPD] module, depending on
912
#' which function is called. If `pattern` is specified then a subset of
1013
#' function names is returned.
1114
#'
1215
#' @examples
1316
#' available_mcmc()
1417
#' available_mcmc("nuts")
1518
#' available_mcmc("rhat|neff")
19+
#'
20+
#' available_ppc()
1621
#' available_ppc("grouped")
1722
#' available_ppc("grouped", invert = TRUE)
1823
#'
19-
available_ppc <- function(pattern = NULL, fixed = FALSE, invert = FALSE) {
20-
.list_module_functions("ppc",
21-
.pattern = pattern,
22-
fixed = fixed,
23-
invert = invert)
24-
}
24+
#' available_ppd()
25+
#' available_ppd("grouped")
26+
#'
27+
#' # can also see which functions that return data are available
28+
#' available_ppc(plots_only = FALSE)
29+
#'
30+
#' # only show the _data functions
31+
#' available_ppc("_data", plots_only = FALSE)
32+
#' available_ppd("_data", plots_only = FALSE)
33+
#' available_mcmc("_data", plots_only = FALSE)
34+
#'
35+
available_ppc <-
36+
function(pattern = NULL,
37+
fixed = FALSE,
38+
invert = FALSE,
39+
plots_only = TRUE) {
40+
.list_module_functions(
41+
.module = "ppc",
42+
.pattern = pattern,
43+
fixed = fixed,
44+
invert = invert,
45+
plots_only = plots_only
46+
)
47+
}
2548

2649
#' @rdname available_ppc
2750
#' @export
28-
available_mcmc <- function(pattern = NULL, fixed = FALSE, invert = FALSE) {
29-
.list_module_functions("mcmc",
30-
.pattern = pattern,
31-
fixed = fixed,
32-
invert = invert)
33-
}
51+
available_ppd <-
52+
function(pattern = NULL,
53+
fixed = FALSE,
54+
invert = FALSE,
55+
plots_only = TRUE) {
56+
.list_module_functions(
57+
.module = "ppd",
58+
.pattern = pattern,
59+
fixed = fixed,
60+
invert = invert,
61+
plots_only = plots_only
62+
)
63+
}
64+
65+
#' @rdname available_ppc
66+
#' @export
67+
available_mcmc <-
68+
function(pattern = NULL,
69+
fixed = FALSE,
70+
invert = FALSE,
71+
plots_only = TRUE) {
72+
.list_module_functions(
73+
.module = "mcmc",
74+
.pattern = pattern,
75+
fixed = fixed,
76+
invert = invert,
77+
plots_only = plots_only
78+
)
79+
}
3480

3581
#' @export
3682
print.bayesplot_function_list <- function(x, ...) {
@@ -48,10 +94,11 @@ print.bayesplot_function_list <- function(x, ...) {
4894

4995
# internal ----------------------------------------------------------------
5096
.list_module_functions <-
51-
function(.module = c("ppc", "mcmc"),
97+
function(.module = c("ppc", "ppd", "mcmc"),
5298
.pattern,
5399
fixed = FALSE,
54-
invert = FALSE) {
100+
invert = FALSE,
101+
plots_only = TRUE) {
55102

56103
.module <- match.arg(.module)
57104

@@ -62,6 +109,17 @@ print.bayesplot_function_list <- function(x, ...) {
62109
)
63110
return_funs <- sort(all_funs)
64111

112+
if (plots_only) {
113+
# drop _data() functions
114+
return_funs <-
115+
grep(
116+
pattern = "_data()",
117+
x = return_funs,
118+
invert = TRUE,
119+
value = TRUE
120+
)
121+
}
122+
65123
if (!is.null(.pattern)) {
66124
return_funs <- grep(
67125
pattern = .pattern,
@@ -71,6 +129,7 @@ print.bayesplot_function_list <- function(x, ...) {
71129
invert = invert
72130
)
73131
}
132+
74133
structure(
75134
return_funs,
76135
class = c("bayesplot_function_list", "character"),

R/bayesplot-colors.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,11 @@ plot.bayesplot_scheme <- function(x, ...) {
203203

204204
# internal -----------------------------------------------------------------
205205

206-
# plot color scheme
207-
# @param scheme A string (length 1) naming a scheme
206+
#' Plot color scheme
207+
#' @noRd
208+
#' @param scheme A string (length 1) naming a scheme. If `NULL` the current
209+
#' scheme is used.
210+
#' @return A ggplot object.
208211
plot_scheme <- function(scheme = NULL) {
209212
if (is.null(scheme)) {
210213
x <- color_scheme_get()
@@ -248,9 +251,8 @@ scheme_level_names <- function() {
248251
}
249252

250253
#' Return a color scheme based on `scheme` argument specified as a string
251-
#'
252254
#' @noRd
253-
#' @param scheme A string (length 1) naming a scheme
255+
#' @param scheme A string (length 1) naming a scheme.
254256
scheme_from_string <- function(scheme) {
255257
if (identical(substr(scheme, 1, 4), "mix-")) {
256258
# user specified a mixed scheme (e.g., "mix-blue-red")
@@ -300,8 +302,8 @@ is_mixed_scheme <- function(x) {
300302

301303
#' Access a subset of the current scheme colors
302304
#' @noRd
303-
#' @param level A character vector of level names in `scheme_level_names()`.
304-
#' The abbreviations "l", "lh", "m", "mh", "d", and "dh" can also be used
305+
#' @param levels A character vector of level names in `scheme_level_names()`.
306+
#' The abbreviations `"l", "lh", "m", "mh", "d", "dh"` can also be used
305307
#' instead of the full names.
306308
#' @return A character vector of color values.
307309
#'

R/bayesplot-ggplot-themes.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ theme_default <-
129129
#' bayesplot_theme_set(theme_dark())
130130
#' mcmc_hist(x) + panel_bg(fill = "black")
131131
#'
132+
#' # reset
133+
#' bayesplot_theme_set()
134+
#'
132135
bayesplot_theme_get <- function() {
133136
if (!identical(.bayesplot_theme_env$gg_current, ggplot2::theme_get())) {
134137
.bayesplot_theme_env$current <- ggplot2::theme_get()

0 commit comments

Comments
 (0)