54
54
# ' `y` and each dataset (row) in `yrep`. For each individual data point
55
55
# ' `y[n]` the average error is the average of the errors for `y[n]` computed
56
56
# ' 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.
57
60
# ' }
58
61
# ' \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.
61
63
# ' }
62
64
# ' \item{`ppc_error_binned()`}{
63
65
# ' Intended for use with binomial data. A separate binned error plot (similar
92
94
# ' ppc_error_scatter_avg(y, yrep)
93
95
# '
94
96
# ' x <- example_x_data()
95
- # ' ppc_error_scatter_avg_vs_x (y, yrep, x)
97
+ # ' ppc_error_scatter_avg (y, yrep, x)
96
98
# '
97
99
# ' \dontrun{
98
100
# ' # binned error plot with binomial model from rstanarm
@@ -217,6 +219,7 @@ ppc_error_scatter <-
217
219
ppc_error_scatter_avg <-
218
220
function (y ,
219
221
yrep ,
222
+ x = NULL ,
220
223
... ,
221
224
stat = " mean" ,
222
225
size = 2.5 ,
@@ -225,19 +228,31 @@ ppc_error_scatter_avg <-
225
228
226
229
y <- validate_y(y )
227
230
yrep <- validate_predictions(yrep , length(y ))
231
+
232
+ if (! missing(x )) {
233
+ qx <- enquo(x )
234
+ x <- validate_x(x , y )
235
+ }
228
236
errors <- compute_errors(y , yrep )
229
237
230
238
stat <- as_tagged_function({{ stat }})
231
239
232
240
ppc_scatter_avg(
233
- y = y ,
241
+ y = if (is_null( x )) y else x ,
234
242
yrep = errors ,
235
243
size = size ,
236
244
alpha = alpha ,
237
245
ref_line = FALSE ,
238
246
stat = stat
239
247
) +
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
+ }
241
256
}
242
257
243
258
@@ -286,6 +301,8 @@ ppc_error_scatter_avg_vs_x <- function(
286
301
) {
287
302
check_ignored_arguments(... )
288
303
304
+ .Deprecated(new = " ppc_error_scatter_avg(y, yrep, x)" )
305
+
289
306
y <- validate_y(y )
290
307
yrep <- validate_predictions(yrep , length(y ))
291
308
qx <- enquo(x )
0 commit comments