Cmdstanr loo_moment_match

Does fit$loo(moment_match = TRUE) work?

1 Like

Unfortunately not. This is because the loo_moment_match() function in the loo package requires arguments like unconstrain_pars and log_prob_upars (described in Moment matching for efficient approximate leave-one-out cross-validation (LOO) — loo_moment_match • loo). These are possible to specify automatically if using RStan but not yet if using any interface based on CmdStan (e.g., RStan has a function rstan::unconstrain_pars() but we don’t have the equivalent in CmdStan yet). It will hopefully be possible in the future!

4 Likes

Note that if you have fitted a costly model with cmdstanr and you need to do loo with moment matching, and you don’t want to re-fit the model, it is possible to recompile the model with rstan for use in conjunction with the draws from cmdstan.

I’ll try to work out exactly how to do this (brms manages it somehow or other) and post back here with a code snippet in the next day or two.

3 Likes

@jsocolar good point! Would be cool to see an example of this.