Error: Object is not a stanreg object. - kfold function

Please also provide the following information in addition to your question:

  • Operating System: Windows 10
  • brms Version: 2.8

I fit several models, but each of them has quite a lot of observations with pareto_k > 0.7,
so I got the warning message:

Warning message:
Found 92 observations with a pareto_k > 0.7 in model ‘fit_under1500_bl101_sos100’. With this many problematic observations, it may be more appropriate to use ‘kfold’ with argument ‘K = 10’ to perform 10-fold cross-validation rather than LOO.

However, when I try to use the kfold function, in the form

kfold(fit, K=10)

where fit is a brms model,
I get the following error:

Error: Object is not a stanreg object.

What could be the reason for that and how can I solve it?

You have overwritten the kfold generic from brms by the one from rstanarm. This will be fixed in the upcoming versions but for now please avoid loading brms and rstanarm in the same session if you want to use kfold, or directly call brms::kfold.