@@ -316,28 +316,7 @@ ppc_error_binned <- function(y, yrep, ..., size = 1, alpha = 0.25) {
316
316
317
317
y <- validate_y(y )
318
318
yrep <- validate_yrep(yrep , y )
319
- errors <- compute_errors(y , yrep )
320
-
321
- N <- length(y )
322
- if (N > = 100 ) {
323
- nbins <- floor(sqrt(N ))
324
- } else if (N > 10 && N < 100 ) {
325
- nbins <- 10
326
- } else {
327
- # if (N <= 10)
328
- nbins <- floor(N / 2 )
329
- }
330
-
331
- S <- nrow(yrep )
332
- binned <- bin_errors(rep_id = 1 , ey = yrep [1 , ], r = errors [1 , ],
333
- nbins = nbins )
334
- if (S > 1 ) {
335
- for (i in 2 : nrow(errors )) {
336
- binned_i <- bin_errors(rep_id = i , ey = yrep [i ,], r = errors [i ,],
337
- nbins = nbins )
338
- binned <- rbind(binned , binned_i )
339
- }
340
- }
319
+ binned <- binned_error_data(y , yrep )
341
320
342
321
mixed_scheme <- is_mixed_scheme(color_scheme_get())
343
322
point_fill <- get_color(ifelse(mixed_scheme , " m" , " d" ))
@@ -377,7 +356,7 @@ ppc_error_binned <- function(y, yrep, ..., size = 1, alpha = 0.25) {
377
356
) +
378
357
bayesplot_theme_get()
379
358
380
- if (S > 1 ) {
359
+ if (nrow( yrep ) > 1 ) {
381
360
graph <- graph +
382
361
facet_wrap(
383
362
facets = ~ rep_id
@@ -412,7 +391,6 @@ grouped_error_data <- function(y, yrep, group) {
412
391
dat
413
392
}
414
393
415
-
416
394
bin_errors <- function (rep_id , ey , r , nbins ) {
417
395
N <- length(ey )
418
396
break_ids <- floor(N * (1 : (nbins - 1 )) / nbins )
@@ -457,4 +435,25 @@ bin_errors <- function(rep_id, ey, r, nbins) {
457
435
}
458
436
459
437
438
+ binned_error_data <- function (y , yrep ) {
439
+ N <- length(y )
440
+ if (N > = 100 ) {
441
+ nbins <- floor(sqrt(N ))
442
+ } else if (N > 10 && N < 100 ) {
443
+ nbins <- 10
444
+ } else {
445
+ # if (N <= 10)
446
+ nbins <- floor(N / 2 )
447
+ }
448
+
449
+ errors <- compute_errors(y , yrep )
450
+ binned_df <- bin_errors(rep_id = 1 , ey = yrep [1 , ], r = errors [1 , ], nbins = nbins )
451
+ if (nrow(yrep ) > 1 ) {
452
+ for (s in 2 : nrow(errors )) {
453
+ binned_s <- bin_errors(rep_id = s , ey = yrep [s ,], r = errors [s ,], nbins = nbins )
454
+ binned_df <- rbind(binned_df , binned_s )
455
+ }
456
+ }
457
+ return (binned_df )
458
+ }
460
459
0 commit comments