Skip to content

Commit 267c532

Browse files
committed
binned_error_data internal
1 parent 67ba2e8 commit 267c532

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

R/ppc-errors.R

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -316,28 +316,7 @@ ppc_error_binned <- function(y, yrep, ..., size = 1, alpha = 0.25) {
316316

317317
y <- validate_y(y)
318318
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)
341320

342321
mixed_scheme <- is_mixed_scheme(color_scheme_get())
343322
point_fill <- get_color(ifelse(mixed_scheme, "m", "d"))
@@ -377,7 +356,7 @@ ppc_error_binned <- function(y, yrep, ..., size = 1, alpha = 0.25) {
377356
) +
378357
bayesplot_theme_get()
379358

380-
if (S > 1) {
359+
if (nrow(yrep) > 1) {
381360
graph <- graph +
382361
facet_wrap(
383362
facets = ~rep_id
@@ -412,7 +391,6 @@ grouped_error_data <- function(y, yrep, group) {
412391
dat
413392
}
414393

415-
416394
bin_errors <- function(rep_id, ey, r, nbins) {
417395
N <- length(ey)
418396
break_ids <- floor(N * (1:(nbins - 1)) / nbins)
@@ -457,4 +435,25 @@ bin_errors <- function(rep_id, ey, r, nbins) {
457435
}
458436

459437

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+
}
460459

0 commit comments

Comments
 (0)