I’ve been playing around with fitting models in
rstanarm::stan_gamm4().The models fit fine but when I use
loo I receive warning messages suggesting I use kfold with K=10 (see MWE below). However, when I use kfold it produces an error that indicates it cannot find the random effect variable (in this case fac). Am I missing something obvious here?
library(rstanarm) library(mgcv) #Simulate a model set.seed(200) dat <- gamSim(6, n=200, scale=2) # Fit the stan model #options(mc.cores=1) # Note this doesn't work in Rstudio 1.2.5042 with R 4.0.0 fit <- rstanarm::stan_gamm4(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, random = ~(1|fac)) # Loo loo_fit <- loo(fit) #Warning message: #Found 200 observations with a pareto_k > 0.7. With this many problematic observations we #recommend calling 'kfold' with argument 'K=10' to perform 10-fold cross-validation rather than LOO. #Kfold kfold(fit, K=10) #Fitting model 1 out of 10 #Error in eval(predvars, data, env) : object 'fac' not found
Note that the above also happens if I supply a folds to the kfold function using one of the convenience functions like