Skip to content

Commit 8850e14

Browse files
committed
Sort tail values
1 parent 02f4466 commit 8850e14

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

R/psis.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ do_psis_i <- function(log_ratios_i, tail_len_i, ...) {
213213
# shift log ratios for safer exponentation
214214
lw_i <- log_ratios_i - max(log_ratios_i)
215215

216-
if (length(unique(utils::tail(log_ratios_i, -tail_len_i))) == 1) {
216+
if (length(unique(utils::tail(sort(log_ratios_i), tail_len_i))) == 1) {
217217
warning(
218218
"Can't fit generalized Pareto distribution ",
219219
"because all tail values are the same.",

tests/testthat/test_psis.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,11 @@ test_that("do_psis_i throws warning if all tail values the same", {
150150
"all tail values are the same"
151151
)
152152
expect_equal(val$pareto_k, Inf)
153+
154+
xx <- c(4, 1, 4, 4, 4, 4, 4, 2, 3, 4, 4)
155+
expect_warning(
156+
val <- do_psis_i(xx, tail_len_i = 6),
157+
"all tail values are the same"
158+
)
159+
expect_equal(val$pareto_k, Inf)
153160
})

0 commit comments

Comments
 (0)