|
48 | 48 | #' Pareto-k's, which may produce optimistic estimates. |
49 | 49 | #' |
50 | 50 | #' For `type="mean"`, `type="var"`, and `type="sd"`, the returned Pareto-k is |
51 | | -#' the maximum of the Pareto-k's for the left and right tail of \eqn{hr} and |
52 | | -#' the right tail of \eqn{r}, where \eqn{r} is the importance ratio and |
53 | | -#' \eqn{h=x} for `type="mean"` and \eqn{h=x^2} for `type="var"` and |
54 | | -#' `type="sd"`. For `type="quantile"`, the returned Pareto-k is the Pareto-k |
55 | | -#' for the right tail of \eqn{r}. |
| 51 | +#' usually the maximum of the Pareto-k's for the left and right tail of \eqn{hr} |
| 52 | +#' and the right tail of \eqn{r}, where \eqn{r} is the importance ratio and |
| 53 | +#' \eqn{h=x} for `type="mean"` and \eqn{h=x^2} for `type="var"` and `type="sd"`. |
| 54 | +#' If \eqn{h} is binary, constant, or not finite, or if `type="quantile"`, the |
| 55 | +#' returned Pareto-k is the Pareto-k for the right tail of \eqn{r}. |
56 | 56 | #' } |
57 | 57 | #' } |
58 | 58 | #' |
@@ -291,10 +291,16 @@ E_loo_khat.matrix <- function(x, psis_object, log_ratios, ...) { |
291 | 291 | h_theta <- x_i |
292 | 292 | r_theta <- exp(log_ratios_i - max(log_ratios_i)) |
293 | 293 | khat_r <- posterior::pareto_khat(r_theta, tail = "right", ndraws_tail = tail_len_i)$khat |
294 | | - if (is.null(x_i)) { |
| 294 | + if (is.null(x_i) || is_constant(x_i) || length(unique(x_i))==2 || |
| 295 | + anyNA(x_i) || any(is.infinite(x_i))) { |
295 | 296 | khat_r |
296 | 297 | } else { |
297 | 298 | khat_hr <- posterior::pareto_khat(h_theta * r_theta, tail = "both", ndraws_tail = tail_len_i)$khat |
298 | | - max(khat_hr, khat_r) |
| 299 | + if (is.na(khat_hr) && is.na(khat_r)) { |
| 300 | + k <- NA |
| 301 | + } else { |
| 302 | + k <- max(khat_hr, khat_r, na.rm=TRUE) |
| 303 | + } |
| 304 | + k |
299 | 305 | } |
300 | 306 | } |
0 commit comments