Skip to content

Commit bd6d26d

Browse files
committed
Merge branch 'master' into remove-arm-dependency
2 parents 707eed8 + b27d9b7 commit bd6d26d

25 files changed

+550
-296
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ SystemRequirements: pandoc (>= 1.12.3), pandoc-citeproc
2222
Depends:
2323
R (>= 3.1.0)
2424
Imports:
25-
dplyr (>= 0.7.1),
25+
dplyr (>= 0.8.0),
2626
ggplot2 (>= 2.2.1),
2727
reshape2,
2828
stats,
2929
utils,
30-
rlang,
31-
ggridges
30+
rlang (>= 0.3.0),
31+
ggridges,
32+
hexbin
3233
Suggests:
3334
gridExtra (>= 2.2.1),
3435
knitr (>= 1.16),

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
<!-- Items for next release go here* -->
88

9+
* MCMC plots now also accept objects with an `as.array` method as
10+
input. (#175, #184)
11+
912
* [`mcmc_trace()`](http://mc-stan.org/bayesplot/reference/MCMC-traces.html)
1013
gains an argument `iter1` which can be used to label the traceplot starting
1114
from the first iteration after warmup. (#14, #155, @mcol)

R/helpers-mcmc.R

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,27 @@ prepare_mcmc_array <- function(x,
1212
x <- df_with_chain2array(x)
1313
} else if (is_chain_list(x)) {
1414
x <- chain_list2array(x)
15+
} else if (is.data.frame(x)) {
16+
# data frame without Chain column
17+
x <- as.matrix(x)
18+
} else if (!is.array(x)) {
19+
x <- as.array(x)
20+
}
21+
22+
stopifnot(is.matrix(x) || is.array(x))
23+
if (is.array(x) && !(length(dim(x)) %in% c(2,3))) {
24+
stop("Arrays should have 2 or 3 dimensions. See help('MCMC-overview').")
25+
}
26+
if (anyNA(x)) {
27+
stop("NAs not allowed in 'x'.")
1528
}
16-
x <- validate_mcmc_x(x)
1729

1830
parnames <- parameter_names(x)
1931
pars <- select_parameters(
2032
explicit = pars,
2133
patterns = regex_pars,
22-
complete = parnames)
34+
complete = parnames
35+
)
2336

2437
# possibly recycle transformations (apply same to all pars)
2538
if (is.function(transformations) ||
@@ -152,21 +165,19 @@ df_with_chain2array <- function(x) {
152165
}
153166

154167

155-
# Check if an object is a list but not a data.frame
168+
# Check if an object is a list (but not a data.frame) that contains
169+
# all 2-D objects
156170
#
157171
# @param x object to check
158172
# @return TRUE or FALSE
159173
is_chain_list <- function(x) {
160-
!is.data.frame(x) && is.list(x)
174+
check1 <- !is.data.frame(x) && is.list(x)
175+
dims <- sapply(x, function(chain) length(dim(chain)))
176+
check2 <- isTRUE(all(dims == 2)) # all elements of list should be matrices/2-D arrays
177+
check1 && check2
161178
}
162179

163180
validate_chain_list <- function(x) {
164-
stopifnot(is_chain_list(x))
165-
dims <- sapply(x, function(chain) length(dim(chain)))
166-
if (!isTRUE(all(dims == 2))) {
167-
stop("If 'x' is a list then all elements must be matrices.")
168-
}
169-
170181
n_chain <- length(x)
171182
for (i in seq_len(n_chain)) {
172183
nms <- colnames(as.matrix(x[[i]]))
@@ -276,25 +287,6 @@ STOP_need_multiple_chains <- function(call. = FALSE) {
276287
}
277288

278289

279-
# Perform some checks on user's 'x' input for MCMC plots
280-
#
281-
# @param x User's 'x' input to one of the mcmc_* functions.
282-
# @return x, unless an error is thrown.
283-
validate_mcmc_x <- function(x) {
284-
stopifnot(!is_df_with_chain(x), !is_chain_list(x))
285-
if (is.data.frame(x)) {
286-
x <- as.matrix(x)
287-
}
288-
289-
stopifnot(is.matrix(x) || is.array(x))
290-
if (anyNA(x)) {
291-
stop("NAs not allowed in 'x'.")
292-
}
293-
294-
x
295-
}
296-
297-
298290
# Validate that transformations match parameter names
299291
validate_transformations <-
300292
function(transformations = list(),

R/mcmc-intervals.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ mcmc_areas_ridges_data <- function(x,
714714
#' @noRd
715715
compute_column_density <- function(df, group_vars, value_var, ...) {
716716
value_var <- enquo(value_var)
717-
group_vars <- enquo(group_vars)
717+
group_vars <- enquos(group_vars)
718718

719719
# Convert the vector of bare column names to a list of symbols
720720
group_cols <- df %>%

R/mcmc-overview.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#' corresponds to a Markov chain. All of the matrices should have the same
1919
#' number of iterations (rows) and parameters (columns), and parameters should
2020
#' have the same names and be in the same order.
21-
#' \item \strong{matrix}: A \code{\link{matrix}} with one column per parameter.
22-
#' If using matrix there should only be a single Markov chain or all chains
23-
#' should already be merged (stacked).
21+
#' \item \strong{matrix (2-D array)}: A \code{\link{matrix}} with one column
22+
#' per parameter. If using matrix there should only be a single Markov chain or
23+
#' all chains should already be merged (stacked).
2424
#' \item \strong{data frame}: There are two types of \link[=data.frame]{data
2525
#' frames} allowed. Either a data frame with one column per parameter (if only
2626
#' a single chain or all chains have already been merged), or a data frame with

R/ppc-discrete.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ ppc_bars_yrep_data <- function(y, yrep, probs, freq = TRUE, group = NULL) {
303303
lo <- function(x) quantile(x, probs[1])
304304
mid <- function(x) quantile(x, probs[2])
305305
hi <- function(x) quantile(x, probs[3])
306-
fs <- dplyr::funs(lo, mid, hi)
306+
fs <- list(lo = lo, mid = mid, hi = hi)
307307

308308
# Set a dummy group for ungrouped data
309309
if (is.null(group)) {

README.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,17 @@ install.packages("bayesplot")
4444
if (!require("devtools")) {
4545
install.packages("devtools")
4646
}
47-
devtools::install_github("stan-dev/bayesplot", dependencies = TRUE, build_vignettes = TRUE)
47+
devtools::install_github("stan-dev/bayesplot", dependencies = TRUE, build_vignettes = FALSE)
4848
```
4949

50-
You can also set `build_vignettes=FALSE` for a faster installation from GitHub (the vignettes
51-
can always be accessed online anytime at [mc-stan.org/bayesplot/articles](http://mc-stan.org/bayesplot/articles/)).
52-
53-
If you are not using the [RStudio IDE](https://www.rstudio.com/) and you get an
54-
error related to "pandoc" you will either need to remove the argument
55-
`build_vignettes=TRUE` (to avoid building the vignettes) or install
56-
[pandoc](http://pandoc.org/) (e.g., `brew install pandoc`) and probably also
57-
pandoc-citeproc (e.g., `brew install pandoc-citeproc`). If you have the
58-
`rmarkdown` R package installed then you can check if you have pandoc by running
59-
the following in R:
60-
61-
```r
62-
rmarkdown::pandoc_available()
63-
```
50+
This installation won't include the vignettes (they take some time to build), but all of the vignettes are
51+
available online at [mc-stan.org/bayesplot/articles](https://mc-stan.org/bayesplot/articles/).
6452

6553

6654
### Examples
6755

68-
Some quick examples using MCMC draws obtained from the [__rstanarm__](https://github.com/stan-dev/rstanarm)
69-
and [__rstan__](https://github.com/stan-dev/rstan) packages.
56+
Some quick examples using MCMC draws obtained from the [__rstanarm__](https://mc-stan.org/rstanarm)
57+
and [__rstan__](https://mc-stan.org/rstann) packages.
7058

7159
```r
7260
library("bayesplot")

man-roxygen/args-mcmc-x.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#' @param x A 3-D array, matrix, list of matrices, or data frame of MCMC draws.
22
#' The \link{MCMC-overview} page provides details on how to specify each these
3-
#' allowed inputs.
3+
#' allowed inputs. It is also possible to use an object with an
4+
#' \code{as.array} method that returns the same kind of 3-D array described on
5+
#' the \link{MCMC-overview} page.

man/MCMC-combos.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/MCMC-diagnostics.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)