Skip to content

Commit 4b695dc

Browse files
committed
add x as argument to ppc_error_binned
1 parent 527c48c commit 4b695dc

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* PPC "avg" functions (`ppc_scatter_avg()`, `ppc_error_scatter_avg()`, etc.) gain a `stat` argument to set the averaging function. (Suggestion of #348, @kruschke).
44
* `ppc_error_scatter_avg_vs_x(x = some_expression)` labels the *x* axis with `some_expression`.
5+
* Add `ppc_dots()` and `ppd_dots()` by @behramulukir (#357)
56

67
# bayesplot 1.13.0
78

R/ppc-errors.R

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,15 @@ ppc_error_scatter_avg_vs_x <- function(
312312
ppc_error_binned <-
313313
function(y,
314314
yrep,
315+
x = NULL,
315316
...,
316317
facet_args = list(),
317318
bins = NULL,
318319
size = 1,
319320
alpha = 0.25) {
320321
check_ignored_arguments(...)
321322

322-
data <- ppc_error_binnned_data(y, yrep, bins = bins)
323+
data <- ppc_error_binnned_data(y, yrep, x = x, bins = bins)
323324
facet_layer <- if (nrow(yrep) == 1) {
324325
geom_ignore()
325326
} else {
@@ -356,7 +357,7 @@ ppc_error_binned <-
356357
color = point_color
357358
) +
358359
labs(
359-
x = "Predicted proportion",
360+
x = if (is.null(x)) "Predicted proportion" else deparse(substitute(x)),
360361
y = "Average Errors \n (with 2SE bounds)"
361362
) +
362363
bayesplot_theme_get() +
@@ -454,24 +455,39 @@ error_avg_label <- function(stat = NULL) {
454455

455456

456457
# Data for binned errors plots
457-
ppc_error_binnned_data <- function(y, yrep, bins = NULL) {
458+
ppc_error_binnned_data <- function(y, yrep, x = NULL, bins = NULL) {
458459
y <- validate_y(y)
459460
yrep <- validate_predictions(yrep, length(y))
460461

462+
if (!is.null(x)) {
463+
x <- validate_x(x, y)
464+
}
465+
461466
if (is.null(bins)) {
462467
bins <- n_bins(length(y))
463468
}
464469

465470
errors <- compute_errors(y, yrep)
466471
binned_errs <- list()
467472
for (s in 1:nrow(errors)) {
468-
binned_errs[[s]] <-
469-
bin_errors(
470-
ey = yrep[s, ],
471-
r = errors[s, ],
472-
bins = bins,
473-
rep_id = s
474-
)
473+
if (is.null(x)) {
474+
binned_errs[[s]] <-
475+
bin_errors(
476+
ey = yrep[s, ],
477+
r = errors[s, ],
478+
bins = bins,
479+
rep_id = s
480+
)
481+
} else {
482+
binned_errs[[s]] <-
483+
bin_errors(
484+
ey = x,
485+
r = errors[s, ],
486+
bins = bins,
487+
rep_id = s
488+
)
489+
}
490+
475491
}
476492

477493
binned_errs <- dplyr::bind_rows(binned_errs)

0 commit comments

Comments
 (0)