Skip to content

Commit 1385c6a

Browse files
committed
combining ppc_error_scatter_avg_vs_x with ppc_error_scatter_avg(x = x)
1 parent 5372336 commit 1385c6a

3 files changed

Lines changed: 208 additions & 8 deletions

File tree

R/ppc-errors.R

Lines changed: 23 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,9 @@ ppc_error_scatter_avg_vs_x <- function(
286301
) {
287302
check_ignored_arguments(...)
288303

304+
.Deprecated(new = "ppc_error_scatter_avg()",
305+
msg = "Use ppc_error_scatter_avg(x = x) instead of ppc_error_scatter_avg_vs_x().")
306+
289307
y <- validate_y(y)
290308
yrep <- validate_predictions(yrep, length(y))
291309
qx <- enquo(x)

0 commit comments

Comments
 (0)