# Loo\_moment\_match fails even after saving all pars

**URL:** <https://discourse.mc-stan.org/t/loo-moment-match-fails-even-after-saving-all-pars/17885>\
**Category:** brms\
**Tags:** loo, fitting-issues\
**Created:** [September 6, 2020, 5:47pm UTC](https://discourse.mc-stan.org/t/loo-moment-match-fails-even-after-saving-all-pars/17885 "2020-09-06T17:47:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Famondir](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/famondir/32/11235_2.png) [@Famondir](https://discourse.mc-stan.org/u/Famondir)\
**Post date:** [September 6, 2020, 5:47pm UTC](https://discourse.mc-stan.org/t/loo-moment-match-fails-even-after-saving-all-pars/17885/1 "2020-09-06T17:47:34Z")

</div>

I try to run loo\_moment\_match() because `loo()` tells me: `Found 7 observations with a pareto_k > 0.7 in model` My target IRT testlet models often exceed 1 GB size. So with a clean R Studio workspace I start my calculation at around 1,5 GB. Then during the calculation the RAM usage goes up to 22 GB (from 32 GB build in). After some time I get the following error:

```
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  Not compatible with requested type: [type=closure; target=double].
Zusätzlich: Warnmeldung:
Error in .local(object, ...) : 
  the model object is not created or not valid
Fehler: Moment matching failed. Perhaps you did not set 'save_all_pars' to TRUE when fitting your model?

```

I definitly saves all pars when I fitted the model (which makes a good amount of the models sizes). I have the assumption that this might be an error generaed deeper in the system. Maybe because of runnig out of RAM? I already set the objectsize in R on 7 GB because I ran in some problems fitting my models earlier. And I set the future.globals.maxSize up as well, because I needed this for `kfold()`.

Edit: This happens also with a model around 300 MB. (I used thinning to get good ESS and maintain small model size). Although the RAM usage doesn’t exceed 5 GB in this case the error above occurs.

Has anyone a clue what the problem is and how I can overcome this obstacle?

Sincerely, Simon Schäfer

Operating System: Win10x64, 18363  
Interface Version: 2.3.1  
Compiler/Toolkit: ?

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [September 18, 2020, 4:35pm UTC](https://discourse.mc-stan.org/t/loo-moment-match-fails-even-after-saving-all-pars/17885/2 "2020-09-18T16:35:42Z")

</div>

Sorry it took so long for someone to reply! I’m not sure about this but I wonder if it’s similar to the error in this other thread:

> [@Comparing complex multivariate models with loo\_compare](https://discourse.mc-stan.org/t/comparing-complex-multivariate-models-with-loo-compare/18071):
>
> I have run two complex multivariate models following this tutorial: [https://cran.r-project.org/web/packages/brms/vignettes/brms\_multivariate.html](https://cran.r-project.org/web/packages/brms/vignettes/brms_multivariate.html). The models follow this format: f1 = as.formula('y1~1+var1+var2+var3+(1+var1+var2+var3|GroupID)') f2 = as.formula('y2~1+var1+var2+var3+(1+var1+var2+var3|GroupID)') f3 = as.formula('y1~1+var1+var2+(1+var1+var2+|GroupID)') f4 = as.formula('y2~1+var1+var2+(1+var1+var2+|GroupID)') model\_of\_interest = brm(f1+f2,data=df,iter=6000,chains=4,cores=4,family="ga…

---

<div class="post-metadata">

**Author:** ![topipa](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@topipa](https://discourse.mc-stan.org/u/topipa)\
**Post date:** [September 24, 2020, 9:07am UTC](https://discourse.mc-stan.org/t/loo-moment-match-fails-even-after-saving-all-pars/17885/3 "2020-09-24T09:07:24Z")

</div>

The error `the model object is not created or not valid` indicates that this may be related to the `stanfit` objects and environments of brms fits. The same error was encountered [here](https://github.com/paul-buerkner/brms/issues/1000) when using multiple cores, and it should now be fixed in the master branch of brms.

Did you encounter this error when using 1 core, or only with multiple cores?

---

<div class="post-metadata">

**Author:** ![Famondir](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/famondir/32/11235_2.png) [@Famondir](https://discourse.mc-stan.org/u/Famondir)\
**Post date:** [October 8, 2020, 12:51pm UTC](https://discourse.mc-stan.org/t/loo-moment-match-fails-even-after-saving-all-pars/17885/4 "2020-10-08T12:51:35Z")

</div>

Thank’s for your reply. The error disappeared somehow in the meantime.

I ran into further problems trying to update some R packages. I had no longer the right so delete the .ddl datas and so updates failed. Reinstalling rstan manually might be a key in this solving process (even if it didn’t helped the first time trying this). But then something in my tidyverse package broke.

So I reinstalled everything after deleting all files from R, RStudio, Rtools. Now it works as expected (I guess).
