Loo moment_match problem

I have never been able to get moment_match = TRUE to work so I generally use reloo = TRUE instead. I recently fitted a model which takes a few hours and requires a few refits when running loo, so I thought I would give moment match another go. But I get this error (similar to errors I have had in the past when attempting moment_match):

Error : $ operator is invalid for atomic vectors
In addition: Warning message:
In parallel::mclapply(X = I, mc.cores = cores, FUN = function(i) loo_moment_match_i_fun(i)) : all scheduled cores encountered errors in user code
Error: Moment matching failed. Perhaps you did not set 'save_pars = save_pars(all = TRUE)' when fitting your model?

Following is the code I used:

mdl_cad_SPS_2 <- 
  brm(
    rating ~ 
      SPS_1_2_sc * SPS_1_3_sc * SPS_2_3_sc + 
      ch1_mode + ch2_mode + ch3_mode + rating_lag1_sc +
      (SPS_1_2_sc * SPS_1_3_sc * SPS_2_3_sc + 
         ch1_mode + ch2_mode + ch3_mode + rating_lag1_sc | 
         participant) +
      (rating_lag1_sc | ch_prog),
    data = data_cad,
    family = cumulative(link = probit_approx),
    prior = c(set_prior("student_t(3, 0, 1)", class = "Intercept"),
              set_prior("student_t(3, 0, 1)", class = "b")),
    inits = 0,
    warmup = 1000, iter = 3500,
    sample_prior = "yes",
    save_pars = save_pars(all = TRUE),
    file = "mdl_cad_SPS_2")
mdl_cad_SPS_2
mcmc_plot(mdl_cad_SPS_2, pars = "^b_")
mdl_cad_SPS_2 <- 
  add_criterion(
    mdl_cad_SPS_2,
    criterion = c("loo", "bayes_R2", "loo_R2"),
    nsamples = 2000,
    moment_match = TRUE,
    overwrite = TRUE
    # reloo = TRUE,
    # inits = 0
  )
  • Operating System: macOS 11.2.1
  • brms Version: 2.14.10
1 Like

Have you tried using the latest dev version of loo from github? We have recently fixed a few things with moment_matching. Perhaps that was one of them.

1 Like

I am running 2.14.10 which I’m pretty sure is the latest dev version.

Ah, but you’re referring to loo - I’ll give that a go!

1 Like

Confirmed – it works with the dev version of loo – many thanks!

2 Likes