MixSIAR icon indicating copy to clipboard operation
MixSIAR copied to clipboard

How do you add more models to jags.mod without running every model over each time?

Open naalipalo opened this issue 2 years ago • 1 comments

Ive run the Alligator script which has 8 models in the loop and produces a jags.mod list, but I wanted to add a new model to the list without having to rerun all 8 models. I am not extremely R savvy, but I was trying to just append or concatenate. When you run the initial loop it generates a large list with 8 elements. When I use c() like: jags.mod<-c(jags.mod, jags.mod9) it turns jags.mod into a large list with 14 elements when it should be now 9. jags.mod9 is a list of 6 elements....so at some level within the initial loop in creating the 8 models, those 8 models themselves are made up of 6 elements. Ultimately I want to be able to use the comparison for LOO analysis of all 9 models. Do I just keep adding the new models to the comparison command instead? If so, how because right now i get errors

> comparison.table <- compare_models(jags.mod, jags.mod9)
Error in if (loo) loo.list[[m]] <- loo::loo(x[[m]]$BUGSoutput$sims.list$loglik) : 
  the condition has length > 1
> comparison.table <- compare_models(c(jags.mod, jags.mod9))
Error in nobs[m] <- dim(x[[m]]$BUGSoutput$sims.list$loglik)[2] : 
  replacement has length zero
In addition: There were 11 warnings (use warnings() to see them)

naalipalo avatar Jan 13 '23 17:01 naalipalo

Have you tried

jags.mod[[9]] <- jags.mod9

https://stackoverflow.com/questions/26508519/how-to-add-elements-to-a-list-in-r-loop

brianstock avatar Apr 01 '23 21:04 brianstock