I need to fit 500 datasets to a specific model using brms package. Here are the codes.
for (n in 1:500) {
data_pathname <- paste0(workpath2,n,".dat")
data <- read.table(data_pathname)
model <- brm(bf(Y~1+X+(1+X|c|group),sigma~1+(1|c|group)),
data,inits=0,cores=4,sample_prior=T)
result <- summary(model)
}
It works well sometimes. But more often R session aborted. The same thing happened both on Rstudio and RGui. The RAM usage of my server keeps lower than 15% when R running. I find the error happened when the summary() function was called.
How can I solve? Appreciate for any reply.
One thing you can try is to add a print(n) or print(data_pathname) and see if your loop always fails for a specific dataset, or if it's random. If it's always the same dataset, you can run it separately and explore the content of model etc.
Also wondering, is it on purpose that you are overwriting result in each iteration of the loop? As written, at the end of running the entire loop you'll have the exact same result as only running for n=500.
Appreciated. I just add a print(n)beforeresult <- summary(model) according to your advice. It didn't help, and now R session aborted before printed n. So now I realize that the error may happened after model <- brm() but not exactly a fault of summary().
It's not always the same dataset. For example, when R aborted, I restart the session and reset 1:500 in for() to 4:500 etc. After few cycles when it absorted again, I restart and reset to 6:500 .
In addition, you are right to find it same as only running for n=500 . Indeed, some parameters of result are assigned to a matrix output as followed.
R session aborting, is typically a more 'involved' issue, than this forum is capable of directly addressing, this is because it doesn't typically relate to poorly written code, or use of code or anything else, but on the quality of the compiled code being relied on, and possibly its interaction with a given target OS.
In such circumstances, the R version, and OS platform you are using, as well as the specific versions of the packages you are using become relevant.
You can use sessionInfo() to gather this info in an easy copy and pasteable form.
You can share your issue with the maintainers of the affected package.
In this case the best venue is Issues · paul-buerkner/brms · GitHub
Here is an example of a similar issue, that was reported and resolved. "R session aborted" when using update() on m1 mac · Issue #1236 · paul-buerkner/brms (github.com)