Skip to content

Commit

Permalink
Merge df74163 into 55e5b20
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Jan 30, 2024
2 parents 55e5b20 + df74163 commit 0eaff59
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 75 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: bayesplot
Type: Package
Title: Plotting for Bayesian Models
Version: 1.10.0.9001
Date: 2023-03-16
Version: 1.11.0
Date: 2024-01-30
Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"), email = "jsg2201@columbia.edu"),
person("Tristan", "Mahr", role = "aut"),
person("Paul-Christian", "Bürkner", role = "ctb"),
Expand All @@ -29,8 +29,8 @@ Depends:
R (>= 3.1.0)
Imports:
dplyr (>= 0.8.0),
ggplot2 (>= 3.0.0),
ggridges,
ggplot2 (>= 3.4.0),
ggridges (>= 0.5.5),
glue,
posterior,
reshape2,
Expand Down
15 changes: 15 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@

S3method("[",neff_ratio)
S3method("[",rhat)
S3method(apply_transformations,array)
S3method(apply_transformations,matrix)
S3method(diagnostic_factor,neff_ratio)
S3method(diagnostic_factor,rhat)
S3method(log_posterior,CmdStanMCMC)
S3method(log_posterior,stanfit)
S3method(log_posterior,stanreg)
S3method(melt_mcmc,matrix)
S3method(melt_mcmc,mcmc_array)
S3method(neff_ratio,CmdStanMCMC)
S3method(neff_ratio,stanfit)
S3method(neff_ratio,stanreg)
S3method(num_chains,data.frame)
S3method(num_chains,mcmc_array)
S3method(num_iters,data.frame)
S3method(num_iters,mcmc_array)
S3method(num_params,data.frame)
S3method(num_params,mcmc_array)
S3method(nuts_params,CmdStanMCMC)
S3method(nuts_params,list)
S3method(nuts_params,stanfit)
S3method(nuts_params,stanreg)
S3method(parameter_names,array)
S3method(parameter_names,default)
S3method(parameter_names,matrix)
S3method(plot,bayesplot_grid)
S3method(plot,bayesplot_scheme)
S3method(pp_check,default)
Expand Down
19 changes: 13 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<!-- See http://style.tidyverse.org/news.html for advice on writing news -->

# bayesplot 1.10.0.9000

* `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.
* Items for next release here
# bayesplot 1.11.0

* Update for new ggplot2 release by @teunbrand in #309
* Add `bins` argument to many histogram plots by @paul-buerkner in #300
* Follow ggplot2 updates on `facet_grid()` and `facet_wrap()` by @heavywatal in #305
* Better `ppc_loo_pit_qq` plots by @avehtari in #307
* Check `prob` is numeric for intervals plots by @tony-stone in #299
* Add `bins` and `breaks` arguments to more histogram and hex plots by @heavywatal in #313
* Replace `size` argument with `linewidth` for `geom_line` and `geom_ridgeline` by @heavywatal in #314
* All LOO plots now accept `psis_object` argument by @jgabry in #311
* `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

# bayesplot 1.10.0

Expand Down Expand Up @@ -49,14 +56,14 @@ previous releases, but the new ones in this release are:
- `ppc_error_hist_grouped()`
- `ppc_error_scatter()`
- `ppc_error_binned()`

* New plotting function `ppc_km_overlay_grouped()`, the grouped variant of
`ppc_km_overlay()`. (#260, @fweber144)

* `ppc_scatter()`, `ppc_scatter_avg()`, and `ppc_scatter_avg_grouped()` gain an
argument `ref_line`, which can be set to `FALSE` to turn off the `x=y` line
drawn behind the scatterplot.

* `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)

* `mcmc_*()` functions now support all draws formats from the **posterior** package. (#277, @Ozan147)
Expand Down
27 changes: 22 additions & 5 deletions R/helpers-mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ prepare_mcmc_array <- function(x,
if (is.matrix(x)) {
x <- x[, pars, drop=FALSE]
if (length(transformations)) {
x <- apply_transformations(x, transformations)
x <- apply_transformations(x, transformations = transformations)
}
x <- array(x, dim = c(nrow(x), 1, ncol(x)))
} else {
x <- x[, , pars, drop = FALSE]
if (length(transformations)) {
x <- apply_transformations(x, transformations)
x <- apply_transformations(x, transformations = transformations)
}
}

Expand Down Expand Up @@ -124,6 +124,8 @@ select_parameters <-
#' @return A molten data frame.
#'
melt_mcmc <- function(x, ...) UseMethod("melt_mcmc")

#' @export
melt_mcmc.mcmc_array <- function(x,
varnames =
c("Iteration", "Chain", "Parameter"),
Expand All @@ -144,6 +146,7 @@ melt_mcmc.mcmc_array <- function(x,
}

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

# Get parameter names from a 3-D array
parameter_names <- function(x) UseMethod("parameter_names")

#' @export
parameter_names.array <- function(x) {
stopifnot(is_3d_array(x))
dimnames(x)[[3]] %||% abort("No parameter names found.")
}
#' @export
parameter_names.default <- function(x) {
colnames(x) %||% abort("No parameter names found.")
}
#' @export
parameter_names.matrix <- function(x) {
colnames(x) %||% abort("No parameter names found.")
}
Expand Down Expand Up @@ -388,10 +395,12 @@ validate_transformations <-
#' functions.
#' @return x, with tranformations having been applied to some parameters.
#'
apply_transformations <- function(x, transformations = list(), ...) {
apply_transformations <- function(x, ...) {
UseMethod("apply_transformations")
}
apply_transformations.matrix <- function(x, transformations = list()) {

#' @export
apply_transformations.matrix <- function(x, ..., transformations = list()) {
pars <- colnames(x)
x_transforms <- validate_transformations(transformations, pars)
for (p in names(x_transforms)) {
Expand All @@ -400,7 +409,9 @@ apply_transformations.matrix <- function(x, transformations = list()) {

x
}
apply_transformations.array <- function(x, transformations = list()) {

#' @export
apply_transformations.array <- function(x, ..., transformations = list()) {
stopifnot(length(dim(x)) == 3)
pars <- dimnames(x)[[3]]
x_transforms <- validate_transformations(transformations, pars)
Expand Down Expand Up @@ -437,17 +448,23 @@ num_chains <- function(x, ...) UseMethod("num_chains")
num_iters <- function(x, ...) UseMethod("num_iters")
num_params <- function(x, ...) UseMethod("num_params")

#' @export
num_params.mcmc_array <- function(x, ...) dim(x)[3]
#' @export
num_chains.mcmc_array <- function(x, ...) dim(x)[2]
#' @export
num_iters.mcmc_array <- function(x, ...) dim(x)[1]
#' @export
num_params.data.frame <- function(x, ...) {
stopifnot("Parameter" %in% colnames(x))
length(unique(x$Parameter))
}
#' @export
num_chains.data.frame <- function(x, ...) {
stopifnot("Chain" %in% colnames(x))
length(unique(x$Chain))
}
#' @export
num_iters.data.frame <- function(x, ...) {
cols <- colnames(x)
stopifnot("Iteration" %in% cols || "Draws" %in% cols)
Expand Down
8 changes: 5 additions & 3 deletions R/mcmc-diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,19 @@ mcmc_acf_bar <-
#' `x <= breaks[1]`, `breaks[1] < x <= breaks[2]`, `x > breaks[2]`).
#' @return A factor the same length as `x` with three levels.
#' @noRd
diagnostic_factor <- function(x, breaks, ...) {
diagnostic_factor <- function(x, ...) {
UseMethod("diagnostic_factor")
}

diagnostic_factor.rhat <- function(x, breaks = c(1.05, 1.1)) {
#' @export
diagnostic_factor.rhat <- function(x, ..., breaks = c(1.05, 1.1)) {
cut(x, breaks = c(-Inf, breaks, Inf),
labels = c("low", "ok", "high"),
ordered_result = FALSE)
}

diagnostic_factor.neff_ratio <- function(x, breaks = c(0.1, 0.5)) {
#' @export
diagnostic_factor.neff_ratio <- function(x, ..., breaks = c(0.1, 0.5)) {
cut(x, breaks = c(-Inf, breaks, Inf),
labels = c("low", "ok", "high"),
ordered_result = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/ppc-discrete.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ ppc_bars_data <-
#' @param y,yrep,group User's already validated `y`, `yrep`, and (if applicable)
#' `group` arguments.
#' @param prob,freq User's `prob` and `freq` arguments.
#' @importFrom dplyr "%>%" ungroup count arrange mutate summarise across full_join rename all_of
#' @importFrom dplyr %>% ungroup count arrange mutate summarise across full_join rename all_of
.ppc_bars_data <- function(y, yrep, group = NULL, prob = 0.9, freq = TRUE) {
alpha <- (1 - prob) / 2
probs <- sort(c(alpha, 0.5, 1 - alpha))
Expand Down
Loading

0 comments on commit 0eaff59

Please sign in to comment.