Skip to content

Commit 0efe3ec

Browse files
Merge pull request #367 from stan-dev/ppc_error_scatter_avg
combining ppc_error_scatter_avg_vs_x with ppc_error_scatter_avg(x = x)
2 parents 5372336 + 6a583ed commit 0efe3ec

File tree

5 files changed

+224
-14
lines changed

5 files changed

+224
-14
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* `ppc_error_scatter_avg_vs_x(x = some_expression)` labels the *x* axis with `some_expression`.
55
* Add `ppc_dots()` and `ppd_dots()` by @behramulukir (#357)
66
* Add `x` argument to `ppc_error_binned` by @behramulukir (#359)
7+
* Add `x` argument to `ppc_error_scatter_avg()` by @behramulukir (#367)
78

89
# bayesplot 1.13.0
910

R/ppc-errors.R

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@
5454
#' `y` and each dataset (row) in `yrep`. For each individual data point
5555
#' `y[n]` the average error is the average of the errors for `y[n]` computed
5656
#' over the the draws from the posterior predictive distribution.
57+
#'
58+
#' When the optional `x` argument is provided, the average error is plotted
59+
#' on the y-axis and the predictor variable `x` is plotted on the x-axis.
5760
#' }
5861
#' \item{`ppc_error_scatter_avg_vs_x()`}{
59-
#' Same as `ppc_error_scatter_avg()`, except the average is plotted on the
60-
#' y-axis and a predictor variable `x` is plotted on the x-axis.
62+
#' Deprecated. Use `ppc_error_scatter_avg(x = x)` instead.
6163
#' }
6264
#' \item{`ppc_error_binned()`}{
6365
#' Intended for use with binomial data. A separate binned error plot (similar
@@ -92,7 +94,7 @@
9294
#' ppc_error_scatter_avg(y, yrep)
9395
#'
9496
#' x <- example_x_data()
95-
#' ppc_error_scatter_avg_vs_x(y, yrep, x)
97+
#' ppc_error_scatter_avg(y, yrep, x)
9698
#'
9799
#' \dontrun{
98100
#' # binned error plot with binomial model from rstanarm
@@ -217,6 +219,7 @@ ppc_error_scatter <-
217219
ppc_error_scatter_avg <-
218220
function(y,
219221
yrep,
222+
x = NULL,
220223
...,
221224
stat = "mean",
222225
size = 2.5,
@@ -225,19 +228,31 @@ ppc_error_scatter_avg <-
225228

226229
y <- validate_y(y)
227230
yrep <- validate_predictions(yrep, length(y))
231+
232+
if (!missing(x)) {
233+
qx <- enquo(x)
234+
x <- validate_x(x, y)
235+
}
228236
errors <- compute_errors(y, yrep)
229237

230238
stat <- as_tagged_function({{ stat }})
231239

232240
ppc_scatter_avg(
233-
y = y,
241+
y = if (is_null(x)) y else x,
234242
yrep = errors,
235243
size = size,
236244
alpha = alpha,
237245
ref_line = FALSE,
238246
stat = stat
239247
) +
240-
labs(x = error_avg_label(stat), y = y_label())
248+
labs(
249+
x = error_avg_label(stat),
250+
y = if (is_null(x)) y_label() else as_label((qx))
251+
) + if (is_null(x)) {
252+
NULL
253+
} else {
254+
coord_flip()
255+
}
241256
}
242257

243258

@@ -286,6 +301,8 @@ ppc_error_scatter_avg_vs_x <- function(
286301
) {
287302
check_ignored_arguments(...)
288303

304+
.Deprecated(new = "ppc_error_scatter_avg(y, yrep, x)")
305+
289306
y <- validate_y(y)
290307
yrep <- validate_predictions(yrep, length(y))
291308
qx <- enquo(x)

man/PPC-errors.Rd

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)