stan-dev/loo

projpred tests failing with posterior 1.6.0

fweber144 opened this issue · 3 comments

With posterior 1.6.0, I get an error in projpred's unit tests that doesn't occur with posterior 1.5.0. This seems to be related to loo::E_loo(), that's why I'm posting here and not on posterior's issue tracker. Reprex (I've updated this reprex to avoid the need to load a binary file):

# From `?loo::E_loo`:
library("loo")
library("rstanarm")
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
d <- data.frame(
  weight = c(ctl, trt),
  group = gl(2, 10, 20, labels = c("Ctl","Trt"))
)
fit <- stan_glm(weight ~ group, data = d, refresh = 0)
yrep <- posterior_predict(fit)
log_ratios <- -1 * log_lik(fit)
r_eff <- relative_eff(exp(-log_ratios), chain_id = rep(1:4, each = 1000))
psis_object <- psis(log_ratios, r_eff = r_eff, cores = 2)
E_loo(yrep, psis_object, type = "mean", log_ratios = log_ratios)
#> Error in posterior::pareto_khat(r_theta, tail = "right", ndraws_tail = tail_len_i)$khat: $ operator is invalid for atomic vectors

Created on 2024-07-04 with reprex v2.1.0

This was with loo v2.7.0 from CRAN. I just saw that v2.8.0 is out; the issue does not occur with v2.8.0 anymore. Thanks!