Skip to content

Commit 29820db

Browse files
committed
Require at least 2 PIT values for boundary correction
1 parent 5dd624d commit 29820db

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

R/ppc-loo.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ ppc_loo_pit_data <-
303303
grid_len = 512) {
304304
if (!is.null(pit)) {
305305
pit <- validate_pit(pit)
306+
if (boundary_correction && length(pit) < 2L) {
307+
abort("At least 2 PIT values are required when 'boundary_correction' is TRUE.")
308+
}
306309
inform("'pit' specified so ignoring 'y','yrep','lw' if specified.")
307310
} else {
308311
suggested_package("rstantools")

tests/testthat/test-ppc-loo.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ test_that("ppc_loo_pit_data validates user-provided pit values", {
7676
ppc_loo_pit_data(pit = "not numeric"),
7777
"is.numeric"
7878
)
79+
expect_error(
80+
ppc_loo_pit_data(pit = c(Inf, -Inf, Inf)),
81+
"between 0 and 1"
82+
)
83+
expect_error(
84+
ppc_loo_pit_data(pit = 0.5, boundary_correction = TRUE),
85+
"At least 2 PIT values"
86+
)
7987
})
8088

8189
test_that("ppc_loo_pit_qq validates user-provided pit values", {

0 commit comments

Comments
 (0)